Module: Libis::Tools::MetsFile::IdContainer

Included in:
Div, File, Map, Representation
Defined in:
lib/libis/tools/mets_file.rb

Instance Method Summary collapse

Instance Method Details

#idObject



20
21
22
23
24
25
# File 'lib/libis/tools/mets_file.rb', line 20

def id
  return @id if @id
  @id = self.class.instance_variable_get('@id') || 1
  self.class.instance_variable_set('@id', @id + 1)
  @id
end

#set_from_hash(h) ⇒ Object



16
17
18
# File 'lib/libis/tools/mets_file.rb', line 16

def set_from_hash(h)
  h.each { |k, v| send "#{k}=", v if respond_to?(k) }
end

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/libis/tools/mets_file.rb', line 27

def to_s
  "#{self.class}:\n" +
      self.instance_variables.map do |var|
        v = self.instance_variable_get(var)
        v = "#{v.class}-#{v.id}" if v.is_a? IdContainer
        v = v.map do |x|
          x.is_a?(IdContainer) ? "#{x.class}-#{x.id}" : x.to_s
        end.join(',') if v.is_a? Array
        " - #{var.to_s.gsub(/^@/, '')}: #{v}"
      end.join("\n")
end