Class: TwistyPuzzles::AbstractMoveParser
- Inherits:
-
Object
- Object
- TwistyPuzzles::AbstractMoveParser
show all
- Defined in:
- lib/twisty_puzzles/abstract_move_parser.rb
Overview
Base class for move parsers.
Instance Method Summary
collapse
Instance Method Details
#move_type_creators ⇒ Object
18
19
20
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 18
def move_type_creators
raise NotImplementedError
end
|
#parse_move(move_string) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 31
def parse_move(move_string)
match = move_string.match(regexp)
if !match || !match.pre_match.empty? || !match.post_match.empty?
raise ArgumentError, "Invalid move #{move_string}."
end
parsed_parts = parse_named_captures(match)
move_type_creators.each do |parser|
return parser.create(parsed_parts) if parser.applies_to?(parsed_parts)
end
raise ArgumentError, "No move type creator applies to #{parsed_parts}"
end
|
#parse_move_part(_name, _string) ⇒ Object
14
15
16
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 14
def parse_move_part(_name, _string)
raise NotImplementedError
end
|
#parse_named_captures(match) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 22
def parse_named_captures(match)
present_named_captures = match.named_captures.compact
present_named_captures.to_h do |name, string|
key = parse_part_key(name).to_sym
value = parse_move_part(name, string)
[key, value]
end
end
|
#parse_part_key(_name) ⇒ Object
10
11
12
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 10
def parse_part_key(_name)
raise NotImplementedError
end
|
#regexp ⇒ Object
6
7
8
|
# File 'lib/twisty_puzzles/abstract_move_parser.rb', line 6
def regexp
raise NotImplementedError
end
|