Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/askoverflow/cli.rb
Instance Method Summary collapse
-
#display_answer(result) ⇒ Object
after a result is selected and the question has been displayed, this displays the result’s full answer.
-
#display_question(result) ⇒ Object
after a result is selected, this displays the result’s full question.
-
#display_results ⇒ Object
Display functions, used to display data to the user display_results displays each result’s basic info.
-
#goodbye ⇒ Object
displays a thankyou message for the user after exit.
-
#greet ⇒ Object
greet, called at program start, greets the user.
-
#prompt_next ⇒ Object
after displaying the full question text asks user to press enter to display the answer.
-
#prompt_result ⇒ Object
asks user for the id number of their desired result.
-
#prompt_return ⇒ Object
asks user to press enter to return to the results page.
-
#prompt_search ⇒ Object
prompt functions used to print requests for user input asks the user to search or exit.
-
#visual_spacer ⇒ Object
Helper function used to simplify displaying messages in a visually pleasing way.
Instance Method Details
#display_answer(result) ⇒ Object
after a result is selected and the question has been displayed, this displays the result’s full answer.
64 65 66 67 68 69 70 |
# File 'lib/askoverflow/cli.rb', line 64 def display_answer(result) 4.times {visual_spacer} puts "++++++++++++++++++++++++++" puts "++++++++++ANSWER++++++++++" puts "++++++++++++++++++++++++++" puts "#{result.full_a}" end |
#display_question(result) ⇒ Object
after a result is selected, this displays the result’s full question
55 56 57 58 59 60 61 |
# File 'lib/askoverflow/cli.rb', line 55 def display_question(result) 10.times {visual_spacer} puts "++++++++++++++++++++++++++" puts "+++++++++QUESTION+++++++++" puts "++++++++++++++++++++++++++" puts "#{result.full_q}" end |
#display_results ⇒ Object
Display functions, used to display data to the user display_results displays each result’s basic info
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/askoverflow/cli.rb', line 44 def display_results Result.all.each_with_index do |r, i| puts "++++++++++++++++++++++++++++++++++++++++++++++++++" puts "|ID:#{i + 1}| #{r.question.slice(0,60)}..." puts "|#{r.answer_count} answer(s) since: #{r.ask_date}" puts "|Tags:\t#{r.}" puts "++++++++++++++++++++++++++++++++++++++++++++++++++" puts "" end end |
#goodbye ⇒ Object
displays a thankyou message for the user after exit
7 8 9 10 11 12 |
# File 'lib/askoverflow/cli.rb', line 7 def goodbye 10.times {visual_spacer} puts "Thanks for using AskOverflow-" puts "I hope we helped" visual_spacer end |
#greet ⇒ Object
greet, called at program start, greets the user
3 4 5 |
# File 'lib/askoverflow/cli.rb', line 3 def greet puts "askoverflow" end |
#prompt_next ⇒ Object
after displaying the full question text asks user to press enter to display the answer
36 37 38 39 40 41 |
# File 'lib/askoverflow/cli.rb', line 36 def prompt_next visual_spacer puts "Press enter to read answer" visual_spacer gets end |
#prompt_result ⇒ Object
asks user for the id number of their desired result
24 25 26 |
# File 'lib/askoverflow/cli.rb', line 24 def prompt_result puts "enter the id of a result to read further, back to do a new search or exit to quit" end |
#prompt_return ⇒ Object
asks user to press enter to return to the results page
28 29 30 31 32 33 |
# File 'lib/askoverflow/cli.rb', line 28 def prompt_return visual_spacer puts "+++enter to return to results+++" visual_spacer gets end |
#prompt_search ⇒ Object
prompt functions used to print requests for user input asks the user to search or exit
20 21 22 |
# File 'lib/askoverflow/cli.rb', line 20 def prompt_search puts "please enter a search or exit: " end |
#visual_spacer ⇒ Object
Helper function used to simplify displaying messages in a visually pleasing way
15 16 17 |
# File 'lib/askoverflow/cli.rb', line 15 def visual_spacer 3.times {puts ""} end |