Class: Ox::XPathSubset::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/em-xmpp/xml_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(t, e, n) ⇒ Query

Returns a new instance of Query.



9
10
11
# File 'lib/em-xmpp/xml_parser.rb', line 9

def initialize(t,e,n)
  @type, @name, @ns = t, e, n
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/em-xmpp/xml_parser.rb', line 8

def name
  @name
end

#nsObject (readonly)

Returns the value of attribute ns.



8
9
10
# File 'lib/em-xmpp/xml_parser.rb', line 8

def ns
  @ns
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/em-xmpp/xml_parser.rb', line 8

def type
  @type
end

Instance Method Details

#find(elem, ns_mapping) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/em-xmpp/xml_parser.rb', line 22

def find(elem, ns_mapping)
  ret = []
  ret << elem if match(elem, ns_mapping)
  case type
  when 'normal'
    elem.nodes.reject{|n| n.is_a?(String)}.each do |n|
      ret << n if match(n, ns_mapping)
    end
  when 'relative', 'anywhere' #TODO: for anywhere, should go to the root first, is that even possible?
    elem.nodes.reject{|n| n.is_a?(String)}.each do |n|
      find(n, ns_mapping).each {|m| ret << m}
    end
  else
    raise NotImplementedError
  end

  ret
end

#match(elem, ns_mapping) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/em-xmpp/xml_parser.rb', line 13

def match(elem, ns_mapping)
  wanted_ns = ns_mapping[ns]

  same_value = elem.value == name 
  same_ns    = elem.xmlns == wanted_ns

  matching = same_value & same_ns
end