module Libis::Tools::MetsFile::MetsObject

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

Public Class Methods

new() click to toggle source

Default initializer

# File lib/libis/tools/mets_objects.rb, line 19
def initialize
  @id = 0
end

Public Instance Methods

id() click to toggle source
# File lib/libis/tools/mets_objects.rb, line 28
def id
  @id
end
set_from_hash(hash) click to toggle source

Take a hash and set class instance attributes. @param [Hash] hash Hash with <attribute_name>, <attribute_value> pairs.

# 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) click to toggle source

Sets the unique id for the instance

# File lib/libis/tools/mets_objects.rb, line 24
def set_id(id)
  @id = id
end
to_s() click to toggle source

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

# 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