class CLI

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

content() click to toggle source
# File lib/cli.rb, line 53
def content
  [divider, @content, quote, divider].each do |thing|
    puts thing
  end
end
display() click to toggle source
# File lib/cli.rb, line 26
def display
  while @mode != 'exit'
    content
    menu
    mode_toggle
  end
end
divider() click to toggle source
# File lib/cli.rb, line 59
def divider
  "\n    ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n"
end
format(text) click to toggle source
# File lib/cli.rb, line 73
def format(text)
  pp = PrettyPrint.new(text,10)
  prettytext = pp.format
end
menu(text = @menu) click to toggle source
mode_toggle() click to toggle source
# 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)
    menu("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() click to toggle source
# File lib/cli.rb, line 22
def quote
  "\n#{format(QUOTE_ARRAY[rand(QUOTE_ARRAY.size)])} - Douglas Adams\n"
end
reset_content() click to toggle source
# 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