class RPath::Adapters::Oga

Public Instance Methods

adapts?(graph) click to toggle source

Returns true iff graph is an Oga::XML::Document or an Oga::XML::Element @param [Object] graph @return [Boolean]

# 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) click to toggle source

Returns the child elements of the given node @param [Oga::XML::Document, Oga::XML::Element] vertex @return [Array<Oga::XML::Element>]

# 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) click to toggle source

Returns the value of the named attribute on the given node. @param [Oga::XML::Document, Oga::XML::Element] vertex @param [String, Symbol] name @return [String, nil]

# 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) click to toggle source

Returns the text content of the given node. @param [Oga::XML::Document, Oga::XML::Element] vertex @return [String, nil]

# File lib/rpath/adapters/oga.rb, line 45
def content(vertex)
  vertex.is_a?(::Oga::XML::Element) ? vertex.text : nil
end
name(vertex) click to toggle source

Returns the name of the given node @param [Oga::XML::Document, Oga::XML::Element] vertex @return [String]

# File lib/rpath/adapters/oga.rb, line 18
def name(vertex)
  vertex.is_a?(::Oga::XML::Element) ? vertex.name : nil
end