Class: Teodoro::XML

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/teodoro/xml.rb

Instance Method Summary collapse

Instance Method Details

#*(path) ⇒ Object

rubocop:disable Naming/BinaryOperatorParameterName



29
30
31
# File 'lib/teodoro/xml.rb', line 29

def *(path) # rubocop:disable Naming/BinaryOperatorParameterName
  xml.css("/*/#{path}").map { |node| self.class.new(Nokogiri::XML(node.to_s)) }
end

#[](*path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/teodoro/xml.rb', line 15

def [](*path)
  node_set = xml.css("/*/#{path.join('/')}")

  raise if node_set.size > 1
  return if node_set.empty?

  node = node_set[0]
  if node.css('*').empty?
    node_set.text
  else
    self.class.new(Nokogiri::XML(node.to_s))
  end
end

#css(path) ⇒ Object



33
34
35
# File 'lib/teodoro/xml.rb', line 33

def css(path)
  xml.css(path)
end