Class: OpenTrons::Labware

Inherits:
Object
  • Object
show all
Defined in:
lib/opentrons/labware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(protocol) ⇒ Labware

Returns a new instance of Labware.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/opentrons/labware.rb', line 5

def initialize(protocol)
  @protocol = protocol
  @labware_hash = {}
  
  #TODO: Better system for dealing with labware defs, including user-specified.

  @labware_definitions = []
  directory = File.expand_path(File.dirname(__FILE__))
  directory = File.join(directory, "..", "..", "definitions")
  Dir[directory + "/*.json"].each do |filename|
    labware_definitions << JSON.parse(File.read(filename))
  end
end

Instance Attribute Details

#labware_definitionsObject

Returns the value of attribute labware_definitions.



3
4
5
# File 'lib/opentrons/labware.rb', line 3

def labware_definitions
  @labware_definitions
end

#labware_hashObject

Returns the value of attribute labware_hash.



3
4
5
# File 'lib/opentrons/labware.rb', line 3

def labware_hash
  @labware_hash
end

#protocolObject

Returns the value of attribute protocol.



3
4
5
# File 'lib/opentrons/labware.rb', line 3

def protocol
  @protocol
end

Instance Method Details

#free_slotsObject



32
33
34
35
36
# File 'lib/opentrons/labware.rb', line 32

def free_slots
  slots = (1..12).to_a.map{|x| x.to_s}
  taken_slots = labware_hash.map {|key, item| item.slot}
  return slots.select{|x| !(taken_slots.include? x)}
end

#inspectObject



51
52
53
# File 'lib/opentrons/labware.rb', line 51

def inspect
  to_s
end

#load(model, slot, display_name = "") ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/opentrons/labware.rb', line 18

def load(model, slot, display_name="")
  generated_id = ""
  loop do
    generated_id = display_name + "-" + rand(100000...999999).to_s
    break if !(labware_hash.key?(generated_id))
  end

  labware_item = LabwareItem.new(self, model, slot, display_name)

  labware_hash[generated_id] = labware_item

  return labware_item
end

#to_hashObject

Returns a pure hash of hashes.



39
40
41
42
43
44
45
# File 'lib/opentrons/labware.rb', line 39

def to_hash
  as_hash = {}
  labware_hash.each do |key, item|
    as_hash[key] = item.to_hash
  end
  return as_hash
end

#to_sObject



47
48
49
# File 'lib/opentrons/labware.rb', line 47

def to_s
  "<OpenTrons::Labware:#{object_id}>"
end