Class: RPath::Adapters::Oga

Inherits:
RPath::Adapter show all
Defined in:
lib/rpath/adapters/oga.rb

Instance Method Summary collapse

Methods inherited from RPath::Adapter

#root

Instance Method Details

#adapts?(graph) ⇒ Boolean

Returns true iff graph is an Oga::XML::Document or an Oga::XML::Element

Parameters:

  • graph (Object)

Returns:

  • (Boolean)


11
12
13
# File 'lib/rpath/adapters/oga.rb', line 11

def adapts?(graph)
  graph.is_a?(::Oga::XML::Element) || graph.is_a?(::Oga::XML::Document)
end

#adjacent(vertex) ⇒ Array<Oga::XML::Element>

Returns the child elements of the given node

Parameters:

Returns:



25
26
27
# File 'lib/rpath/adapters/oga.rb', line 25

def adjacent(vertex)
  vertex.children.select { |child| child.is_a?(::Oga::XML::Element) }
end

#attribute(vertex, name) ⇒ String?

Returns the value of the named attribute on the given node.

Parameters:

Returns:

  • (String, nil)


33
34
35
36
37
38
39
40
# File 'lib/rpath/adapters/oga.rb', line 33

def attribute(vertex, name)
  if vertex.is_a?(::Oga::XML::Element)
    attr = vertex.attr(name)
    attr && attr.value
  else
    nil
  end
end

#content(vertex) ⇒ String?

Returns the text content of the given node.

Parameters:

Returns:

  • (String, nil)


45
46
47
# File 'lib/rpath/adapters/oga.rb', line 45

def content(vertex)
  vertex.is_a?(::Oga::XML::Element) ? vertex.text : nil
end

#name(vertex) ⇒ String

Returns the name of the given node

Parameters:

Returns:

  • (String)


18
19
20
# File 'lib/rpath/adapters/oga.rb', line 18

def name(vertex)
  vertex.is_a?(::Oga::XML::Element) ? vertex.name : nil
end