Class: Lutaml::Model::MappingHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/lutaml/model/mapping_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMappingHash

Returns a new instance of MappingHash.



6
7
8
9
10
11
# File 'lib/lutaml/model/mapping_hash.rb', line 6

def initialize
  @ordered = false
  @item_order = []

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



51
52
53
54
55
56
# File 'lib/lutaml/model/mapping_hash.rb', line 51

def method_missing(method_name, *args)
  value = self[method_name] || self[method_name.to_s]
  return value if value

  super
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



4
5
6
# File 'lib/lutaml/model/mapping_hash.rb', line 4

def node
  @node
end

#orderedObject

Returns the value of attribute ordered.



4
5
6
# File 'lib/lutaml/model/mapping_hash.rb', line 4

def ordered
  @ordered
end

Instance Method Details

#assign_or_append_value(key, value) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/lutaml/model/mapping_hash.rb', line 39

def assign_or_append_value(key, value)
  self[key] = if self[key]
                [self[key], value].flatten
              else
                value
              end
end

#fetch(key) ⇒ Object



17
18
19
# File 'lib/lutaml/model/mapping_hash.rb', line 17

def fetch(key)
  self[key.to_s] || self[key.to_sym]
end

#item_orderObject



13
14
15
# File 'lib/lutaml/model/mapping_hash.rb', line 13

def item_order
  @item_order
end

#item_order=(order) ⇒ Object



25
26
27
28
29
# File 'lib/lutaml/model/mapping_hash.rb', line 25

def item_order=(order)
  raise "`item order` must be an array" unless order.is_a?(Array)

  @item_order = order
end

#key_exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/lutaml/model/mapping_hash.rb', line 21

def key_exist?(key)
  key?(key.to_s) || key?(key.to_sym)
end

#ordered?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/lutaml/model/mapping_hash.rb', line 47

def ordered?
  @ordered
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/lutaml/model/mapping_hash.rb', line 58

def respond_to_missing?(method_name, include_private = false)
  key_present = key?(method_name) || key?(method_name.to_s)
  return true if key_present

  super
end

#textObject



31
32
33
# File 'lib/lutaml/model/mapping_hash.rb', line 31

def text
  self["#cdata-section"] || self["text"]
end

#text?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/lutaml/model/mapping_hash.rb', line 35

def text?
  key?("#cdata-section") || key?("text")
end