Class: Krikri::XmlParser::Value

Inherits:
Parser::Value show all
Defined in:
lib/krikri/parsers/xml_parser.rb

Overview

An XML Parser Value node class

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser::Value

#[], #attribute?, #child?, #method_missing, #respond_to_missing

Constructor Details

#initialize(node, namespaces) ⇒ Value

Returns a new instance of Value


37
38
39
40
41
# File 'lib/krikri/parsers/xml_parser.rb', line 37

def initialize(node, namespaces)
  node = node.root if node.xml?
  @node = node
  @namespaces = namespaces
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Krikri::Parser::Value

Instance Attribute Details

#namespacesObject

Returns the value of attribute namespaces


34
35
36
# File 'lib/krikri/parsers/xml_parser.rb', line 34

def namespaces
  @namespaces
end

#nodeObject

Returns the value of attribute node


34
35
36
# File 'lib/krikri/parsers/xml_parser.rb', line 34

def node
  @node
end

Instance Method Details

#attributesObject


43
44
45
# File 'lib/krikri/parsers/xml_parser.rb', line 43

def attributes
  @node.attributes.keys.map(&:to_sym)
end

#childrenObject


47
48
49
50
51
52
# File 'lib/krikri/parsers/xml_parser.rb', line 47

def children
  @node.element_children.map do |child|
    return child.name unless child.namespace
    "#{@namespaces.key(child.namespace.href)}:#{child.name}"
  end
end

#valueObject


54
55
56
# File 'lib/krikri/parsers/xml_parser.rb', line 54

def value
  @node.content
end

#values?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/krikri/parsers/xml_parser.rb', line 58

def values?
  !select_values.empty?
end