Class: IPTC::MultipleHash
- Inherits:
-
Object
- Object
- IPTC::MultipleHash
- Defined in:
- lib/iptc/multiple_hash.rb
Overview
This structure is too complicated.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns one or more values for a given key if there is only one value, do not send an array back but send the value instead.
- #add(marker, hash) ⇒ Object
- #each ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize ⇒ MultipleHash
constructor
A new instance of MultipleHash.
- #keys ⇒ Object
Constructor Details
#initialize ⇒ MultipleHash
Returns a new instance of MultipleHash.
10 11 12 |
# File 'lib/iptc/multiple_hash.rb', line 10 def initialize() @internal = Hash.new end |
Instance Method Details
#[](key) ⇒ Object
Returns one or more values for a given key if there is only one value, do not send an array back but send the value instead.
25 26 27 28 29 30 31 32 33 |
# File 'lib/iptc/multiple_hash.rb', line 25 def [](key) if has_key?(key) if @internal[key].length == 1 return @internal[key][0] else return @internal[key] end end end |
#add(marker, hash) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/iptc/multiple_hash.rb', line 13 def add marker, hash hash.each do |key,value| @internal[key] ||= [] @internal[key] << MultipleHashItem.new(marker,key,value) end end |
#each ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/iptc/multiple_hash.rb', line 37 def each @internal.each do |key, values| values.each do |value| yield value end end end |
#has_key?(key) ⇒ Boolean
19 20 21 |
# File 'lib/iptc/multiple_hash.rb', line 19 def has_key?(key) return @internal.has_key?(key) end |
#keys ⇒ Object
34 35 36 |
# File 'lib/iptc/multiple_hash.rb', line 34 def keys return @internal.keys end |