Class: Howdy::UI
- Inherits:
-
Object
- Object
- Howdy::UI
- Defined in:
- lib/howdy/ui.rb
Overview
Layer for user interface. In the simplest case it’s just standard output.
Class Method Summary collapse
- .choose_dictionary ⇒ Object
-
.display(message) ⇒ Object
Displays message on defined output (stdout by default).
-
.error(message) ⇒ Object
Displays message on defined output (stderr by default).
-
.list_dictionaries ⇒ Object
prints list of available dictionaries.
-
.prompt(message) ⇒ Object
Display message and wait for user input.
Class Method Details
.choose_dictionary ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/howdy/ui.rb', line 32 def choose_dictionary list_dictionaries range = Dictionary.range_available index = prompt("Choose [#{range}]").to_i unless range.include?(index) error "No such dictionary. Choose one number of [#{range}]" exit 1 end Dictionary.available[index-1] end |
.display(message) ⇒ Object
Displays message on defined output (stdout by default)
8 9 10 |
# File 'lib/howdy/ui.rb', line 8 def display() puts end |
.error(message) ⇒ Object
Displays message on defined output (stderr by default)
13 14 15 |
# File 'lib/howdy/ui.rb', line 13 def error() $stderr.puts end |
.list_dictionaries ⇒ Object
prints list of available dictionaries
18 19 20 21 22 23 |
# File 'lib/howdy/ui.rb', line 18 def list_dictionaries display "Available dictionaries:" Dictionary.available.each_with_index do |dict, idx| display " #{idx+1}. #{dict.dict_label} - #{dict.dict_description}" end end |
.prompt(message) ⇒ Object
Display message and wait for user input. Returns captured data
27 28 29 30 |
# File 'lib/howdy/ui.rb', line 27 def prompt() print "#{}: " $stdin.gets end |