Class: RubyWarrior::UI
- Inherits:
-
Object
- Object
- RubyWarrior::UI
- Defined in:
- lib/ruby_warrior/ui.rb
Class Method Summary collapse
- .ask(msg) ⇒ Object
-
.choose(item, options) ⇒ Object
REFACTORME.
- .gets ⇒ Object
- .print(msg) ⇒ Object
- .puts(msg) ⇒ Object
- .puts_with_delay(msg) ⇒ Object
- .request(msg) ⇒ Object
Class Method Details
.ask(msg) ⇒ Object
27 28 29 |
# File 'lib/ruby_warrior/ui.rb', line 27 def ask(msg) request("#{msg} [#{R18n.t.answer.yes_no}] ") == R18n.t.answer.yes_initial end |
.choose(item, options) ⇒ Object
REFACTORME
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_warrior/ui.rb', line 32 def choose(item, ) if .length == 1 response = .first else .each_with_index do |option, i| if option.kind_of? Array puts "[#{i+1}] #{option.last}" else puts "[#{i+1}] #{option}" end end choice = request(R18n.t.item.choose_typing_number(item)) response = [choice.to_i-1] end if response.kind_of? Array response.first else response end end |
.gets ⇒ Object
18 19 20 |
# File 'lib/ruby_warrior/ui.rb', line 18 def gets Config.in_stream ? Config.in_stream.gets : '' end |
.print(msg) ⇒ Object
14 15 16 |
# File 'lib/ruby_warrior/ui.rb', line 14 def print(msg) Config.out_stream.print(msg) if Config.out_stream end |
.puts(msg) ⇒ Object
4 5 6 |
# File 'lib/ruby_warrior/ui.rb', line 4 def puts(msg) Config.out_stream.puts(msg) if Config.out_stream end |
.puts_with_delay(msg) ⇒ Object
8 9 10 11 12 |
# File 'lib/ruby_warrior/ui.rb', line 8 def puts_with_delay(msg) result = puts(msg) sleep(Config.delay) if Config.delay result end |
.request(msg) ⇒ Object
22 23 24 25 |
# File 'lib/ruby_warrior/ui.rb', line 22 def request(msg) print(msg) gets.chomp end |