Module: Libis::Tools::MetsFile::MetsObject

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

Overview

Generic module that provides code shortcuts for the Representation, Div and File classes.

Instance Method Summary collapse

Instance Method Details

#idObject



27
28
29
# File 'lib/libis/tools/mets_objects.rb', line 27

def id
  @id
end

#initializeObject

Default initializer



18
19
20
# File 'lib/libis/tools/mets_objects.rb', line 18

def initialize
  @id = 0
end

#set_from_hash(hash) ⇒ Object

Take a hash and set class instance attributes.

Parameters:

  • hash (Hash)

    Hash with <attribute_name>, <attribute_value> pairs.



13
14
15
# File 'lib/libis/tools/mets_objects.rb', line 13

def set_from_hash(hash)
  hash.each { |key, value| send "#{key}=", value if respond_to?(key) }
end

#set_id(id) ⇒ Object

Sets the unique id for the instance



23
24
25
# File 'lib/libis/tools/mets_objects.rb', line 23

def set_id(id)
  @id = id
end

#to_sObject

Convert structure to String. Can be used for debugging to show what is stored.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/libis/tools/mets_objects.rb', line 32

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? MetsObject
        v = v.map do |x|
          x.is_a?(MetsObject) ? "#{x.class}-#{x.id}" : x.to_s
        end.join(',') if v.is_a? Array
        " - #{var.to_s.gsub(/^@/, '')}: #{v}"
      end.join("\n")
end