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 13 |
# 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
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 |
#show ⇒ Object
19 20 21 |
# File 'lib/table.rb', line 19 def show table end |
#table_style ⇒ Object
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 |