Class: IPTC::MultipleHash

Inherits:
Object
  • Object
show all
Defined in:
lib/iptc/multiple_hash.rb

Overview

This structure is too complicated.

Instance Method Summary collapse

Constructor Details

#initializeMultipleHash

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

#eachObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/iptc/multiple_hash.rb', line 19

def has_key?(key)
  return @internal.has_key?(key)
end

#keysObject



34
35
36
# File 'lib/iptc/multiple_hash.rb', line 34

def keys
  return @internal.keys
end