Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/table.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #create_table ⇒ Object
- #hidden_answer(answer) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #show ⇒ Object
- #table_style ⇒ Object
- #update(guess_number, guess, number_correct, position, answer) ⇒ Object
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
7 8 9 10 11 12 |
# File 'lib/table.rb', line 7 def initialize @rows = [] @rows << ['Answer', '????', 'XX', 'XX'] @table = create_table table_style end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/table.rb', line 4 def rows @rows end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/table.rb', line 4 def table @table end |
Instance Method Details
#create_table ⇒ Object
36 37 38 39 |
# File 'lib/table.rb', line 36 def create_table Terminal::Table.new headings: %w(Round Guess Color Pos), rows: rows end |
#hidden_answer(answer) ⇒ Object
22 23 24 |
# File 'lib/table.rb', line 22 def hidden_answer(answer) @rows[0] = ['Answer', answer.join(''), 'XX', 'XX'] end |
#show ⇒ Object
18 19 20 |
# File 'lib/table.rb', line 18 def show table end |
#table_style ⇒ Object
14 15 16 |
# File 'lib/table.rb', line 14 def table_style table.style = { width: 40, padding_left: 3, border_x: '=', border_i: 'X' } end |
#update(guess_number, guess, number_correct, position, answer) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/table.rb', line 26 def update(guess_number, guess, number_correct, position, answer) if guess_number < 10 @rows << [guess_number, guess, number_correct, position] else hidden_answer(answer) end @table = create_table table_style end |