Class: Engine::CLI
- Inherits:
-
Object
- Object
- Engine::CLI
- Defined in:
- lib/engine/cli.rb
Instance Attribute Summary collapse
-
#card ⇒ Object
readonly
Returns the value of attribute card.
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
-
#initialize(cards) ⇒ CLI
constructor
A new instance of CLI.
- #next_card ⇒ Object
- #rate_card(score) ⇒ Object
- #readline_loop ⇒ Object
Constructor Details
Instance Attribute Details
#card ⇒ Object (readonly)
Returns the value of attribute card.
3 4 5 |
# File 'lib/engine/cli.rb', line 3 def card @card end |
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
3 4 5 |
# File 'lib/engine/cli.rb', line 3 def cards @cards end |
Instance Method Details
#next_card ⇒ Object
8 9 10 |
# File 'lib/engine/cli.rb', line 8 def next_card @card = cards.sample end |
#rate_card(score) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/engine/cli.rb', line 12 def rate_card(score) puts "Before : " + card.inspect card.rate(score).tap do |new_card| @cards = @cards.update_card(card, new_card) @card = new_card end puts "After : " + card.inspect end |
#readline_loop ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/engine/cli.rb', line 21 def readline_loop next_card loop do input = Readline.readline("#{card.data.first} > ", true) exit unless input case input when /s/, "" puts card.data.last when /[0-5]/ rate_card(input.to_i) next_card end end end |