Class: Nabokov::Informator

Inherits:
Object
  • Object
show all
Defined in:
lib/nabokov/helpers/informator.rb

Overview

This class is heavily based on the Interviewer class from the Danger gem The original link is github.com/danger/danger/blob/master/lib/danger/commands/init_helpers/interviewer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cork_board) ⇒ Informator

Returns a new instance of Informator.



9
10
11
# File 'lib/nabokov/helpers/informator.rb', line 9

def initialize(cork_board)
  @ui = cork_board
end

Instance Attribute Details

#no_waitingObject

Returns the value of attribute no_waiting.



7
8
9
# File 'lib/nabokov/helpers/informator.rb', line 7

def no_waiting
  @no_waiting
end

#uiObject

Returns the value of attribute ui.



7
8
9
# File 'lib/nabokov/helpers/informator.rb', line 7

def ui
  @ui
end

Instance Method Details

#ask_with_answers(question, possible_answers) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nabokov/helpers/informator.rb', line 46

def ask_with_answers(question, possible_answers)
  ui.print("\n#{question}? [")
  print_possible_answers(possible_answers)
  answer = ""
  loop do
    show_prompt
    answer = read_answer(possible_answers)

    break if possible_answers.map(&:downcase).include? answer

    ui.print "\nPossible answers are ["
    print_possible_answers(possible_answers)
  end
  answer
end

#error(message) ⇒ Object



36
37
38
# File 'lib/nabokov/helpers/informator.rb', line 36

def error(message)
  ui.puts(message.red)
end

#important(message) ⇒ Object



25
26
27
28
29
30
# File 'lib/nabokov/helpers/informator.rb', line 25

def important(message)
  i = message.length + 8
  inform("-" * i)
  inform("--- " + message + " ---")
  inform("-" * i)
end

#inform(message) ⇒ Object



21
22
23
# File 'lib/nabokov/helpers/informator.rb', line 21

def inform(message)
  ui.puts(message.green)
end

#say(message) ⇒ Object



17
18
19
# File 'lib/nabokov/helpers/informator.rb', line 17

def say(message)
  ui.puts(message)
end

#show_promptObject



13
14
15
# File 'lib/nabokov/helpers/informator.rb', line 13

def show_prompt
  ui.print("> ".bold.green)
end

#wait_for_returnObject



40
41
42
43
44
# File 'lib/nabokov/helpers/informator.rb', line 40

def wait_for_return
  STDOUT.flush
  STDIN.gets unless @no_waiting
  ui.puts
end

#warn(message) ⇒ Object



32
33
34
# File 'lib/nabokov/helpers/informator.rb', line 32

def warn(message)
  ui.puts(message.yellow)
end