class HTML::Conditions

:nodoc:

def initialize(hash)

:nodoc:
def initialize(hash)
  super()
  hash = { :content => hash } unless Hash === hash
  hash = keys_to_symbols(hash)
  hash.each do |k,v|
    case k
      when :tag, :content then
        # keys are valid, and require no further processing
      when :attributes then
        hash[k] = keys_to_strings(v)
      when :parent, :child, :ancestor, :descendant, :sibling, :before,
              :after
        hash[k] = Conditions.new(v)
      when :children
        hash[k] = v = keys_to_symbols(v)
        v.each do |k,v2|
          case k
            when :count, :greater_than, :less_than
              # keys are valid, and require no further processing
            when :only
              v[k] = Conditions.new(v2)
            else
              raise "illegal key #{k.inspect} => #{v2.inspect}"
          end
        end
      else
        raise "illegal key #{k.inspect} => #{v.inspect}"
    end
  end
  update hash
end

def keys_to_strings(hash)

def keys_to_strings(hash)
  hash.keys.inject({}) do |h,k|
    h[k.to_s] = hash[k]
    h
  end
end

def keys_to_symbols(hash)

def keys_to_symbols(hash)
  hash.keys.inject({}) do |h,k|
    raise "illegal key #{k.inspect}" unless k.respond_to?(:to_sym)
    h[k.to_sym] = hash[k]
    h
  end
end