Module: Predicated::Predicate::NodeToPredicate

Defined in:
lib/predicated/from/xml.rb

Constant Summary collapse

OPERATION_TAG_TO_CLASS =
{
  "equal" => Equal, 
  "greaterThan" => GreaterThan, 
  "lessThan" => LessThan, 
  "greaterThanOrEqualTo" => GreaterThanOrEqualTo, 
  "lessThanOrEqualTo" => LessThanOrEqualTo
}

Class Method Summary collapse

Class Method Details

.convert(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/predicated/from/xml.rb', line 21

def self.convert(node)
  
  node = next_non_text_node(node)
  
  if node.name == "and"
    left = next_non_text_node(node.children[0])
    right = next_non_text_node(left.next)
    And.new(convert(left), convert(right))
  elsif node.name == "or"
    left = next_non_text_node(node.children[0])
    right = next_non_text_node(left.next)
    Or.new(convert(left), convert(right))
  elsif node.name == "not"
    inner = next_non_text_node(node.children[0])
    Not.new(convert(inner))
  elsif operation_class=OPERATION_TAG_TO_CLASS[node.name]
    left = next_non_text_node(node.children[0])
    right = next_non_text_node(left.next)
    operation_class.new(left.text, right.text)
  else
    raise DontKnowWhatToDoWithThisXmlTag.new(node.name)
  end
end

.next_non_text_node(node) ⇒ Object



45
46
47
48
49
50
# File 'lib/predicated/from/xml.rb', line 45

def self.next_non_text_node(node)
  while node.text?
    node = node.next
  end
  node
end