Class: Jigit::Informator
- Inherits:
-
Object
- Object
- Jigit::Informator
- Defined in:
- lib/jigit/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
-
#no_delay ⇒ Object
Returns the value of attribute no_delay.
-
#no_waiting ⇒ Object
Returns the value of attribute no_waiting.
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #ask(question) ⇒ Object
- #ask_with_answers(question, possible_answers, is_numerated = false) ⇒ Object
- #error(message) ⇒ Object
- #header(title) ⇒ Object
- #important(message) ⇒ Object
- #inform(message) ⇒ Object
-
#initialize(cork_board) ⇒ Informator
constructor
A new instance of Informator.
- #link(url) ⇒ Object
- #pause(time) ⇒ Object
- #say(message) ⇒ Object
- #show_prompt ⇒ Object
- #wait_for_return ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(cork_board) ⇒ Informator
Returns a new instance of Informator.
9 10 11 |
# File 'lib/jigit/helpers/informator.rb', line 9 def initialize(cork_board) @ui = cork_board end |
Instance Attribute Details
#no_delay ⇒ Object
Returns the value of attribute no_delay.
7 8 9 |
# File 'lib/jigit/helpers/informator.rb', line 7 def no_delay @no_delay end |
#no_waiting ⇒ Object
Returns the value of attribute no_waiting.
7 8 9 |
# File 'lib/jigit/helpers/informator.rb', line 7 def no_waiting @no_waiting end |
#ui ⇒ Object
Returns the value of attribute ui.
7 8 9 |
# File 'lib/jigit/helpers/informator.rb', line 7 def ui @ui end |
Instance Method Details
#ask(question) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jigit/helpers/informator.rb', line 60 def ask(question) STDIN.reopen(File.open("/dev/tty", "r")) answer = "" loop do ui.puts "\n#{question}?" show_prompt answer = STDIN.gets.chomp break unless answer.empty? ui.print "\nYou need to provide an answer." end answer end |
#ask_with_answers(question, possible_answers, is_numerated = false) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jigit/helpers/informator.rb', line 77 def ask_with_answers(question, possible_answers, is_numerated = false) STDIN.reopen(File.open("/dev/tty", "r")) ui.print("\n#{question}? [") possible_answers_to_print = is_numerated ? possible_answers.map.with_index { |answer, index| "#{index}. #{answer}" } : possible_answers print_possible_answers(possible_answers_to_print) answer = "" loop do show_prompt answer = read_answer(possible_answers) if is_numerated numerated_answer = begin Integer(answer) rescue break end break if numerated_answer < 0 && possible_answers.count <= numerated_answer answer = possible_answers[numerated_answer] end break if possible_answers.include? answer ui.print "\nPossible answers are [" print_possible_answers(possible_answers) end answer end |
#error(message) ⇒ Object
50 51 52 |
# File 'lib/jigit/helpers/informator.rb', line 50 def error() ui.puts(.red) end |
#header(title) ⇒ Object
33 34 35 36 37 |
# File 'lib/jigit/helpers/informator.rb', line 33 def header(title) say title.yellow say "" pause 0.6 end |
#important(message) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/jigit/helpers/informator.rb', line 39 def important() i = .length + 8 inform("-" * i) inform("--- " + + " ---") inform("-" * i) end |
#inform(message) ⇒ Object
21 22 23 |
# File 'lib/jigit/helpers/informator.rb', line 21 def inform() ui.puts(.green) end |
#link(url) ⇒ Object
25 26 27 |
# File 'lib/jigit/helpers/informator.rb', line 25 def link(url) say " -> " + url.underline + "\n" end |
#pause(time) ⇒ Object
29 30 31 |
# File 'lib/jigit/helpers/informator.rb', line 29 def pause(time) sleep(time) unless @no_waiting end |
#say(message) ⇒ Object
17 18 19 |
# File 'lib/jigit/helpers/informator.rb', line 17 def say() ui.puts() end |
#show_prompt ⇒ Object
13 14 15 |
# File 'lib/jigit/helpers/informator.rb', line 13 def show_prompt ui.print("> ".bold.green) end |
#wait_for_return ⇒ Object
54 55 56 57 58 |
# File 'lib/jigit/helpers/informator.rb', line 54 def wait_for_return STDOUT.flush STDIN.gets unless @no_delay ui.puts end |
#warn(message) ⇒ Object
46 47 48 |
# File 'lib/jigit/helpers/informator.rb', line 46 def warn() ui.puts(.yellow) end |