Class: CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

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

#contentObject



53
54
55
56
57
# File 'lib/cli.rb', line 53

def content
  [divider, @content, quote, divider].each do |thing|
    puts thing
  end
end

#displayObject



26
27
28
29
30
31
32
# File 'lib/cli.rb', line 26

def display
  while @mode != 'exit'
    content
    menu
    mode_toggle
  end
end

#dividerObject



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


63
64
65
66
67
68
69
70
71
# File 'lib/cli.rb', line 63

def menu(text = @menu)
  menu = [divider,
   format(text),
   divider]
   menu.each do |thing|
     puts thing
   end
  @mode = gets.chomp.downcase
end

#mode_toggleObject



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)
    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

#quoteObject



22
23
24
# File 'lib/cli.rb', line 22

def quote
  "\n#{format(QUOTE_ARRAY[rand(QUOTE_ARRAY.size)])} - Douglas Adams\n"
end

#reset_contentObject



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