Class: TwistyPuzzles::LetterScheme
- Inherits:
-
Object
- Object
- TwistyPuzzles::LetterScheme
- Defined in:
- lib/twisty_puzzles/letter_scheme.rb
Overview
Letter scheme that maps stickers to letters.
Direct Known Subclasses
Instance Method Summary collapse
- #alphabet ⇒ Object
- #canonicalize_letter(_letter) ⇒ Object
- #for_letter(part_type, desired_letter) ⇒ Object
-
#initialize ⇒ LetterScheme
constructor
A new instance of LetterScheme.
- #letter(piece) ⇒ Object
- #parse_part(part_type, part_string) ⇒ Object (also: #parse_buffer)
- #valid_letter?(letter) ⇒ Boolean
Constructor Details
#initialize ⇒ LetterScheme
Returns a new instance of LetterScheme.
8 9 10 11 12 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 8 def initialize alphabet.each do |letter| raise "Uncanonical letter #{letter} in alphabet." if letter != canonicalize_letter(letter) end end |
Instance Method Details
#alphabet ⇒ Object
27 28 29 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 27 def alphabet raise NotImplementedError end |
#canonicalize_letter(_letter) ⇒ Object
31 32 33 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 31 def canonicalize_letter(_letter) raise NotImplementedError end |
#for_letter(part_type, desired_letter) ⇒ Object
18 19 20 21 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 18 def for_letter(part_type, desired_letter) canonicalized_letter = canonicalize_letter(desired_letter) part_type::ELEMENTS.find { |e| letter(e) == canonicalized_letter } end |
#letter(piece) ⇒ Object
14 15 16 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 14 def letter(piece) alphabet[piece.piece_index] end |
#parse_part(part_type, part_string) ⇒ Object Also known as: parse_buffer
35 36 37 38 39 40 41 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 35 def parse_part(part_type, part_string) if valid_letter?(part_string) for_letter(part_type, part_string) else part_type.parse(part_string) end end |
#valid_letter?(letter) ⇒ Boolean
23 24 25 |
# File 'lib/twisty_puzzles/letter_scheme.rb', line 23 def valid_letter?(letter) alphabet.include?(canonicalize_letter(letter)) end |