Class: Sashite::Ggn::Ruleset::Source::Destination
- Inherits:
-
Object
- Object
- Sashite::Ggn::Ruleset::Source::Destination
- 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
-
#destination?(location) ⇒ Boolean
Check if location is a valid destination from this source.
-
#destinations ⇒ Array<String>
Return all valid destinations from this source.
-
#initialize(data) ⇒ Destination
constructor
Create a new Destination.
-
#to(destination) ⇒ Engine
Specify the destination location.
Constructor Details
#initialize(data) ⇒ Destination
Create a new Destination
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
53 54 55 |
# File 'lib/sashite/ggn/ruleset/source/destination.rb', line 53 def destination?(location) @data.key?(location) end |
#destinations ⇒ Array<String>
Return all valid destinations from this source
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
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 |