Class: Table

Inherits:
Object
  • Object
show all
Defined in:
lib/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

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

#rowsObject (readonly)

Returns the value of attribute rows.



4
5
6
# File 'lib/table.rb', line 4

def rows
  @rows
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/table.rb', line 4

def table
  @table
end

Instance Method Details

#create_tableObject



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

#showObject



18
19
20
# File 'lib/table.rb', line 18

def show
  table
end

#table_styleObject



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