Class: GameOfLife::Inputters::SimpleStringInputter
- Inherits:
-
Object
- Object
- GameOfLife::Inputters::SimpleStringInputter
- Defined in:
- lib/game_of_life/inputters/simple_string_inputter.rb
Overview
parses an input string for the board data
Instance Method Summary collapse
- #convert_cryptic_symbol_to_state(symbol) ⇒ Object private
-
#parse(raw_input) ⇒ 2D Array<Symbol>
Parses board’s data from a string.
Instance Method Details
#convert_cryptic_symbol_to_state(symbol) ⇒ Object (private)
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/game_of_life/inputters/simple_string_inputter.rb', line 33 def convert_cryptic_symbol_to_state(symbol) case symbol when 'X' :live when '-' :dead else raise ArgumentError, "Don't know how to convert #{symbol} into a Cell's state" end end |
#parse(raw_input) ⇒ 2D Array<Symbol>
Parses board’s data from a string.
23 24 25 26 27 28 29 30 |
# File 'lib/game_of_life/inputters/simple_string_inputter.rb', line 23 def parse(raw_input) rows = raw_input.split("\n") rows.map! { |row| row.split(' ') } rows.map! do |row| row.map! { |symbol| convert_cryptic_symbol_to_state(symbol) } end rows end |