Class: MDEXClient::MData::Node
- Inherits:
-
Object
- Object
- MDEXClient::MData::Node
show all
- Defined in:
- lib/mdex_client/mdata/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(element_or_hash = nil) ⇒ Node
Returns a new instance of Node.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/mdex_client/mdata/node.rb', line 8
def initialize(element_or_hash=nil)
return if element_or_hash.nil?
case element_or_hash
when Nokogiri::XML::Element, Nokogiri::XML::NodeSet
@element = element_or_hash
initialize_from_element!
when Hash
element_or_hash.each do |key, value|
send("#{key}=", value)
end
else
raise "Invalid type to initialize a MDEXClient::MData::Node: #{element_or_hash.class}"
end
end
|
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
6
7
8
|
# File 'lib/mdex_client/mdata/node.rb', line 6
def element
@element
end
|
Instance Method Details
#dimension_value_state_list(search, dimension_values) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/mdex_client/mdata/node.rb', line 56
def dimension_value_state_list(search, dimension_values)
query = "#{search}/mdata:DimensionValue | #{search}/mdata:DimensionValueReference"
xpath(query).collect do |dv|
dimension_values[dv["Id"].to_i]
end
end
|
#initialize_from_element! ⇒ Object
Subclasses should override this to initialize the appropriate fields from the provided XML element.
26
27
|
# File 'lib/mdex_client/mdata/node.rb', line 26
def initialize_from_element!
end
|
#property_list(search) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/mdex_client/mdata/node.rb', line 49
def property_list(search)
xpath(search).inject({}) do |memo, property|
memo[property["Key"]] = property.text
memo
end
end
|
#record_list(search) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mdex_client/mdata/node.rb', line 37
def record_list(search)
records = xpath("#{search}/mdata:Record").collect do |child|
Record.new(child)
end
xpath("#{search}/mdata:AggregateRecord").each do |child|
records << AggregateRecord.new(child)
end
records
end
|
#xpath(search) ⇒ Object
33
34
35
|
# File 'lib/mdex_client/mdata/node.rb', line 33
def xpath(search)
@element.xpath(search, MDEXClient::Client::NAMESPACES)
end
|