Class: Mead::ComponentPart
- Inherits:
-
Object
- Object
- Mead::ComponentPart
- Defined in:
- lib/mead/component_part.rb
Instance Attribute Summary collapse
-
#containers ⇒ Object
Returns the value of attribute containers.
-
#item_location ⇒ Object
Returns the value of attribute item_location.
-
#level ⇒ Object
Returns the value of attribute level.
-
#series_sequence ⇒ Object
Returns the value of attribute series_sequence.
-
#unitdate ⇒ Object
Returns the value of attribute unitdate.
-
#unitid ⇒ Object
Returns the value of attribute unitid.
-
#unittitle ⇒ Object
Returns the value of attribute unittitle.
Instance Method Summary collapse
-
#==(another_cp) ⇒ Object
FIXME: must be a better way to implement my own equality.
-
#[](attribute) ⇒ Object
FIXME: temporary method while refactoring.
-
#initialize(opts = {}) ⇒ ComponentPart
constructor
A new instance of ComponentPart.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ComponentPart
Returns a new instance of ComponentPart.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mead/component_part.rb', line 7 def initialize(opts={}) @item_location = opts[:item_location] if opts[:item_location] @unittitle = opts[:unittitle] if opts[:unittitle] @unitdate = opts[:unitdate] if opts[:unitdate] @unitid = opts[:unitid] if opts[:unitid] @level = opts[:level] if opts[:level] self.series_sequence = opts[:series_sequence] if opts[:series_sequence] if opts[:containers] @containers = [] # FIXME: What is a better way to insure the Array-ness of containers? if opts[:containers].is_a? Array opts[:containers].each do |container| if container.is_a?(Mead::Container) @containers << container else raise 'containers must have only Mead::Containers' end end else raise 'containers must be in an Array' end end end |
Instance Attribute Details
#containers ⇒ Object
Returns the value of attribute containers.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def containers @containers end |
#item_location ⇒ Object
Returns the value of attribute item_location.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def item_location @item_location end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def level @level end |
#series_sequence ⇒ Object
Returns the value of attribute series_sequence.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def series_sequence @series_sequence end |
#unitdate ⇒ Object
Returns the value of attribute unitdate.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def unitdate @unitdate end |
#unitid ⇒ Object
Returns the value of attribute unitid.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def unitid @unitid end |
#unittitle ⇒ Object
Returns the value of attribute unittitle.
3 4 5 |
# File 'lib/mead/component_part.rb', line 3 def unittitle @unittitle end |
Instance Method Details
#==(another_cp) ⇒ Object
FIXME: must be a better way to implement my own equality. How to get all the symbols for the possible attributes for an instance of a class?
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mead/component_part.rb', line 47 def ==(another_cp) return false if !another_cp.is_a?(Mead::ComponentPart) [:unittitle, :unitdate, :unitid, :level, :series_sequence, :containers, :item_location].each do |attribute| if self.send(attribute) != another_cp.send(attribute) return false end end return true end |
#[](attribute) ⇒ Object
FIXME: temporary method while refactoring
65 66 67 |
# File 'lib/mead/component_part.rb', line 65 def [](attribute) self.send(attribute) end |
#to_json(*a) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/mead/component_part.rb', line 69 def to_json(*a) h = { 'json_class' => self.class.name } self.instance_variables.each do |var| h[var.sub('@','').to_sym] = self.send(var.sub('@','').to_sym) end h.to_json(*a) end |