Class: XmlMapper::XmlMapperHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/xml_mapper_hash.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



3
4
5
# File 'lib/xml_mapper_hash.rb', line 3

def node
  @node
end

#xml_pathObject

Returns the value of attribute xml_path.



3
4
5
# File 'lib/xml_mapper_hash.rb', line 3

def xml_path
  @xml_path
end

Class Method Details

.from_path_and_node(new_path, new_node) ⇒ Object



5
6
7
8
9
10
# File 'lib/xml_mapper_hash.rb', line 5

def self.from_path_and_node(new_path, new_node)
  hash = self.new
  hash.xml_path = new_path
  hash.node = new_node
  hash
end

Instance Method Details

#clone_attributes_into!(to_be_cloned_attributes, into_keys) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/xml_mapper_hash.rb', line 12

def clone_attributes_into!(to_be_cloned_attributes, into_keys)
  hashes_from_into_keys(into_keys).each do |sub_attributes|
    [to_be_cloned_attributes].flatten.each do |clone_key, clone_value|
      sub_attributes[clone_key.to_sym] ||= self[clone_key.to_sym] if self.has_key?(clone_key.to_sym)
    end
  end
end

#hashes_from_into_keys(into_keys) ⇒ Object



20
21
22
# File 'lib/xml_mapper_hash.rb', line 20

def hashes_from_into_keys(into_keys)
  [into_keys].flatten.map { |key| self[key] }.flatten.compact
end

#strip_attributes!(hash) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/xml_mapper_hash.rb', line 24

def strip_attributes!(hash)
  hash.each do |key, value|
    if value.is_a?(Hash)
      strip_attributes!(value)
    elsif value.is_a?(Array)
      value.map { |array_value| strip_attributes!(array_value) }
    elsif value.respond_to?(:strip!)
      value.strip!
      hash[key] = nil if value.length == 0
    end
  end
end