Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/cli.rb
Instance Method Summary collapse
- #content ⇒ Object
- #display ⇒ Object
- #divider ⇒ Object
- #format(text) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #menu(text = @menu) ⇒ Object
- #mode_toggle ⇒ Object
- #quote ⇒ Object
- #reset_content ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 |
# File 'lib/cli.rb', line 12 def initialize @zip = Location.new.zip @weather = WeatherAPI.new(@zip).returnhash @mode = 'english' @content = mode_toggle @allowable = ['english', 'doge', 'ermahgerd', 'ermagerd', 'pirate', 'pig latin', 'emoji', 'exit'] @menu = "No matter where you travel in the galaxy, we have you covered: no Babel Fish required. Would you like to view content in English, Emoji, Ermahgerd, Pirate, Pig Latin, or Doge? You can type Exit to exit at any time." display end |
Instance Method Details
#content ⇒ Object
53 54 55 56 57 |
# File 'lib/cli.rb', line 53 def content [divider, @content, quote, divider].each do |thing| puts thing end end |
#display ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/cli.rb', line 26 def display while @mode != 'exit' content mode_toggle end end |
#divider ⇒ Object
59 60 61 |
# File 'lib/cli.rb', line 59 def divider "\n ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n" end |
#format(text) ⇒ Object
73 74 75 76 |
# File 'lib/cli.rb', line 73 def format(text) pp = PrettyPrint.new(text,10) prettytext = pp.format end |
#menu(text = @menu) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/cli.rb', line 63 def (text = @menu) = [divider, format(text), divider] .each do |thing| puts thing end @mode = gets.chomp.downcase end |
#mode_toggle ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cli.rb', line 34 def mode_toggle if @mode == 'english' @content = format(reset_content) elsif @mode == 'doge' @content = format(reset_content.dogeify) elsif @mode == 'ermahgerd' || @mode == 'ermagerd' @content = format(Ermahgerd.translate(reset_content)) elsif @mode == 'pirate' @content = format(TalkLikeAPirate.translate(reset_content)) elsif @mode == 'pig latin' @content = format(reset_content.to_pig_latin) elsif @mode == 'emoji' @content = Emojify.new(@weather[:city], @weather[:id].to_s[0], @weather[:temp].to_i.to_s, CODES[@weather[:id].to_s]).output elsif !@allowable.include?(@mode) ("I'm sorry, I didn't understand that. Would you like to view content in English, Emoji, Ermahgerd, Pirate, Pig Latin, or Doge? You can type Exit to exit at any time.") mode_toggle end end |
#quote ⇒ Object
22 23 24 |
# File 'lib/cli.rb', line 22 def quote "\n#{format(QUOTE_ARRAY[rand(QUOTE_ARRAY.size)])} - Douglas Adams\n" end |
#reset_content ⇒ Object
8 9 10 |
# File 'lib/cli.rb', line 8 def reset_content @content = "Welcome to the Flatiron Guide to the Galaxy! Remember: DON'T PANIC. Looks like you've ended up on Earth in #{@weather[:city]}. Too bad about its imminent destruction. #{GREETINGS[@weather[:id].to_s[0]]}! It's #{@weather[:temp].to_i} degrees with #{CODES[@weather[:id].to_s]}. And don't forget your towel." end |