Class: Howdy::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/howdy/ui.rb

Overview

Layer for user interface. In the simplest case it’s just standard output.

Class Method Summary collapse

Class Method Details

.choose_dictionaryObject



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(message)
  puts message
end

.error(message) ⇒ Object

Displays message on defined output (stderr by default)



13
14
15
# File 'lib/howdy/ui.rb', line 13

def error(message)
  $stderr.puts message
end

.list_dictionariesObject

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(message)
  print "#{message}: "
  $stdin.gets
end