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
13
# 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



37
38
39
40
# File 'lib/table.rb', line 37

def create_table
  Terminal::Table.new :headings => ['Round', 'Guess', 'Color', 'Pos'],
                      :rows => rows
end

#hidden_answer(answer) ⇒ Object



23
24
25
# File 'lib/table.rb', line 23

def hidden_answer(answer)
    @rows[0] = ['Answer', answer.join(''), 'XX','XX']
end

#showObject



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

def show
  table
end

#table_styleObject



15
16
17
# File 'lib/table.rb', line 15

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



27
28
29
30
31
32
33
34
35
# File 'lib/table.rb', line 27

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