Module: Libis::Tools::MetsFile::MetsObject
Overview
Generic module that provides code shortcuts for the Representation, Div and File classes.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize ⇒ Object
Default initializer.
-
#set_from_hash(hash) ⇒ Object
Take a hash and set class instance attributes.
-
#set_id(id) ⇒ Object
Sets the unique id for the instance.
-
#to_s ⇒ Object
Convert structure to String.
Instance Method Details
#id ⇒ Object
28 29 30 |
# File 'lib/libis/tools/mets_objects.rb', line 28 def id @id end |
#initialize ⇒ Object
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.
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_s ⇒ Object
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 |