Module: CaTissue::Storable

Included in:
Container, Specimen
Defined in:
lib/catissue/util/storable.rb

Overview

The Storable mix-in adds methods for a domain class which can be stored and implements the storable_type, position and position_class methods.

Constant Summary collapse

Position =

Position is an alias for CaTissue::AbstractPosition.

CaTissue::AbstractPosition

Instance Method Summary collapse

Instance Method Details

#containerObject

Returns the Container which holds this Storable, or nil if none.



11
12
13
# File 'lib/catissue/util/storable.rb', line 11

def container
  position and position.container
end

#move_to(arg) ⇒ Position Also known as: >>

Moves this storable from its current Position, if any, to the location given by the argument.

Parameters:

Options Hash (arg):

  • :in (CaTissue::Container)

    the target container

  • :at (CaRuby::Coordinate, (Integer, Integer))

    the target coordinates

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/catissue/util/storable.rb', line 22

def move_to(arg)
  case arg
    when CaTissue::Container then arg.add(self)
    when CaTissue::Location then
      loc = arg
      loc.container.add(self, loc.coordinate)
    when Hash then
      dest = arg[:in]
      if at.nil? then raise ArgumentError.new("#{self} move_to container :in option not found") end
      coord = arg[:at]
      dest = CaTissue::Location.new(dest, coord) if coord
      move_to(dest)
    else raise ArgumentError.new("Target location is neither a Container nor a Location: #{arg.class.qp}")
  end
  position
end