Module: CaTissue::Storable

Included in:
Container, Specimen
Defined in:
lib/catissue/helpers/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.



12
13
14
# File 'lib/catissue/helpers/storable.rb', line 12

def container
  position and position.container
end

#move_to(*args) ⇒ Position Also known as: >>

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

Parameters:

Options Hash (*args):

  • :in (CaTissue::Container)

    the target container

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

    the target coordinates

Returns:

See Also:



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

def move_to(*args)
  arg = args.shift
  case arg
    when CaTissue::Container then arg.add(self, *args)
    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