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



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

def id
  @id
end

#initializeObject

Default initializer



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

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.



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

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



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

def set_id(id)
  @id = id
end

#to_sObject

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



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

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