Class: Sashite::Ggn::Ruleset::Source::Destination

Inherits:
Object
  • Object
show all
Defined in:
lib/sashite/ggn/ruleset/source/destination.rb,
lib/sashite/ggn/ruleset/source/destination/engine.rb

Overview

Represents movement possibilities from a specific source

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Destination

Create a new Destination

Parameters:

  • data (Hash)

    Destinations data structure



16
17
18
19
20
# File 'lib/sashite/ggn/ruleset/source/destination.rb', line 16

def initialize(data)
  @data = data

  freeze
end

Instance Method Details

#destination?(location) ⇒ Boolean

Check if location is a valid destination from this source

Examples:

destination.destination?("e2") # => true

Parameters:

  • location (String)

    Destination location

Returns:

  • (Boolean)


53
54
55
# File 'lib/sashite/ggn/ruleset/source/destination.rb', line 53

def destination?(location)
  @data.key?(location)
end

#destinationsArray<String>

Return all valid destinations from this source

Examples:

destination.destinations # => ["d1", "d2", "e2", "f2", "f1"]

Returns:

  • (Array<String>)

    Destination locations



42
43
44
# File 'lib/sashite/ggn/ruleset/source/destination.rb', line 42

def destinations
  @data.keys
end

#to(destination) ⇒ Engine

Specify the destination location

Examples:

engine = destination.to("e2")

Parameters:

  • destination (String)

    Destination location (CELL coordinate or HAND “*”)

Returns:

  • (Engine)

    Movement evaluation engine

Raises:

  • (KeyError)

    If destination not found from this source



30
31
32
33
34
# File 'lib/sashite/ggn/ruleset/source/destination.rb', line 30

def to(destination)
  raise ::KeyError, "Destination not found: #{destination}" unless destination?(destination)

  Engine.new(*@data.fetch(destination))
end