Module: SharedMethods

Included in:
Exiv2::ExifData, Exiv2::IptcData, Exiv2::XmpData
Defined in:
lib/exiv2/shared_methods.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



28
29
30
# File 'lib/exiv2/shared_methods.rb', line 28

def [](key) 
  self.to_hash[key]
end

#[]=(key, value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/exiv2/shared_methods.rb', line 32

def []=(key, value)
  delete_all(key)
  if value.is_a?(Array)
    value.each do |v|
      self.add(key, v)
    end
  else
    self.add(key, value)
  end
end

#delete_all(key) ⇒ Object



43
44
45
46
47
48
# File 'lib/exiv2/shared_methods.rb', line 43

def delete_all(key)
  del = true
  while(del) do
    del = self.delete(key)
  end 
end

#inspectObject



20
21
22
23
24
25
26
# File 'lib/exiv2/shared_methods.rb', line 20

def inspect
  items = []
  self.to_hash.sort.each do |k,v|
    items << %Q["#{k}"=>#{v.inspect}]
  end
  "#<#{self.class.name}: {#{items.join(', ')}}>"
end

#to_hashObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/exiv2/shared_methods.rb', line 3

def to_hash
  result = {}

  self.each do |key, value|
    if result[key]
      if result[key].is_a? Array
        result[key] << value
      else
        result[key] = [result[key], value]
      end
    else
      result[key] = value
    end
  end
  result
end