Module: CaTissue::Position

Included in:
AbstractPosition, SpecimenArrayContent
Defined in:
lib/catissue/helpers/position.rb

Overview

The Position mix-in encapsulates the location of an occupant in a holder. Classes which include Position are required to implement the column, row, occupant and holder methods. The occupant must be a Storable. The holder must be a Container.

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

Returns whether other is an instance of this position’s class with the same occupant and equal location.

Returns:

  • (Boolean)

    whether other is an instance of this position’s class with the same occupant and equal location

See Also:



14
15
16
# File 'lib/catissue/helpers/position.rb', line 14

def ==(other)
  self.class === other and occupant == other.occupant and location == other.location
end

#coordinateCoordinate

Returns the read-only coordinate with this AbstractPosition’s Location#row and Location#column.

Returns:



20
21
22
# File 'lib/catissue/helpers/position.rb', line 20

def coordinate
  location.coordinate
end

#locationLocation

Returns the location of this Position.

Returns:

  • (Location)

    the location of this Position



25
26
27
28
29
30
31
32
# File 'lib/catissue/helpers/position.rb', line 25

def location
  @location ||= Location.new
  # always ensure that the location is consistent with the Java state
  @location.holder = holder
  @location.row = row
  @location.column = column
  @location
end

#location=(value) ⇒ Object

Parameters:

  • the (Location)

    location value to set



35
36
37
38
39
40
# File 'lib/catissue/helpers/position.rb', line 35

def location=(value)
  @location = value || Location.new
  self.holder = @location.holder
  self.row = @location.row
  self.column = @location.column
end

#to_a(Integer, Integer)

Returns this Position’s zero-based (Location#column, Location#row) tuple.

Returns:



49
50
51
# File 'lib/catissue/helpers/position.rb', line 49

def to_a
  [column, row]
end

#unspecified?Boolean

Returns whether either the column or the row is nil.

Returns:

  • (Boolean)

    whether either the column or the row is nil



43
44
45
# File 'lib/catissue/helpers/position.rb', line 43

def unspecified?
  column.nil? or row.nil?
end

#validate_localObject

Raises:

  • (Jinx::ValidationError)

    if the holder cannot hold the occupant type



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/catissue/helpers/position.rb', line 54

def validate_local
  super
  logger.debug { "Validating that #{holder} can hold #{occupant}..." }
  curr_occ = holder[column, row]
  if curr_occ.nil? then
    unless holder.can_hold_child?(occupant) then
      reason = holder.full? ? "it is full" : "the occupant type is not among the supported types #{holder.container_type.child_types.qp}"
      raise Jinx::ValidationError.new("#{holder} cannot hold #{occupant} since #{reason}")
    end
  elsif curr_occ != occupant
    raise Jinx::ValidationError.new("#{holder} cannot hold #{occupant} since the location #{[colum, row]} is already occupied by #{curr_occ}")
  end
end