Class: Mead::ComponentPart

Inherits:
Object
  • Object
show all
Defined in:
lib/mead/component_part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#containersObject

Returns the value of attribute containers.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def containers
  @containers
end

#item_locationObject

Returns the value of attribute item_location.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def item_location
  @item_location
end

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def level
  @level
end

#series_sequenceObject

Returns the value of attribute series_sequence.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def series_sequence
  @series_sequence
end

#unitdateObject

Returns the value of attribute unitdate.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def unitdate
  @unitdate
end

#unitidObject

Returns the value of attribute unitid.



3
4
5
# File 'lib/mead/component_part.rb', line 3

def unitid
  @unitid
end

#unittitleObject

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