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.



39
40
41
42
43
# File 'lib/krikri/parsers/xml_parser.rb', line 39

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.



36
37
38
# File 'lib/krikri/parsers/xml_parser.rb', line 36

def namespaces
  @namespaces
end

#nodeObject

Returns the value of attribute node.



36
37
38
# File 'lib/krikri/parsers/xml_parser.rb', line 36

def node
  @node
end

Instance Method Details

#attributesObject



45
46
47
# File 'lib/krikri/parsers/xml_parser.rb', line 45

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

#childrenObject



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

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

#valueObject



56
57
58
# File 'lib/krikri/parsers/xml_parser.rb', line 56

def value
  @node.content
end

#values?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/krikri/parsers/xml_parser.rb', line 60

def values?
  !select_values.empty?
end