Module: JSONSelect::Ast::PseudoSelector

Defined in:
lib/json_select/ast/pseudo_selector.rb

Instance Method Summary collapse

Instance Method Details

#to_astObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/json_select/ast/pseudo_selector.rb', line 3

def to_ast
  if respond_to?(:e)
    ast = { :pseudo_function => a.text_value, :a => 0 , :b => 0 }
    ast.merge!(e.to_ast)
    ast
  else
    case a.text_value

    when 'first-child'
      { :pseudo_function => 'nth-child', :a => 0, :b => 1 }

    when 'last-child'
      { :pseudo_function => 'nth-last-child', :a => 0, :b => 1 }

    else
      { :pseudo_class => a.text_value }

    end
  end
end