Class: Sashite::Ggn::Ruleset::Source
- Inherits:
-
Object
- Object
- Sashite::Ggn::Ruleset::Source
- Defined in:
- lib/sashite/ggn/ruleset/source.rb,
lib/sashite/ggn/ruleset/source/destination.rb,
lib/sashite/ggn/ruleset/source/destination/engine.rb
Overview
Represents movement possibilities for a piece type
Defined Under Namespace
Classes: Destination
Instance Method Summary collapse
-
#from(source) ⇒ Destination
Specify the source location for the piece.
-
#initialize(data) ⇒ Source
constructor
Create a new Source.
-
#source?(location) ⇒ Boolean
Check if location is a valid source for this piece.
-
#sources ⇒ Array<String>
Return all valid source locations for this piece.
Constructor Details
#initialize(data) ⇒ Source
Create a new Source
15 16 17 18 19 |
# File 'lib/sashite/ggn/ruleset/source.rb', line 15 def initialize(data) @data = data freeze end |
Instance Method Details
#from(source) ⇒ Destination
Specify the source location for the piece
29 30 31 32 33 |
# File 'lib/sashite/ggn/ruleset/source.rb', line 29 def from(source) raise ::KeyError, "Source not found: #{source}" unless source?(source) Destination.new(@data.fetch(source)) end |
#source?(location) ⇒ Boolean
Check if location is a valid source for this piece
52 53 54 |
# File 'lib/sashite/ggn/ruleset/source.rb', line 52 def source?(location) @data.key?(location) end |
#sources ⇒ Array<String>
Return all valid source locations for this piece
41 42 43 |
# File 'lib/sashite/ggn/ruleset/source.rb', line 41 def sources @data.keys end |