Module: Menus

Defined in:
lib/concerns/menus.rb

Instance Method Summary collapse

Instance Method Details

#add_zipObject



45
46
47
48
49
50
# File 'lib/concerns/menus.rb', line 45

def add_zip
    puts "Please enter the zip code:".colorize(:light_green)
    zip = gets.strip
    Settings.add_zip(zip)
    main_menu
end

#choose_forecast(zip) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/concerns/menus.rb', line 2

def choose_forecast(zip)
    entries = []
    entries << GemMenu::Entry.new("5 day forecast", method(:display_5_day), {:parameters => zip})
    entries << GemMenu::Entry.new("Single day detail", method(:display_single_detail), {:parameters => zip})
    entries << GemMenu::Entry.new("Hourly", method(:display_hourly), {:parameters => zip})
    optional = {:previous_menu => method(:main_menu)}
    GemMenu::Menu.new("Choose forecast to view", entries, optional_args=optional)
end

#delete_zip(zip) ⇒ Object



52
53
54
55
# File 'lib/concerns/menus.rb', line 52

def delete_zip(zip)
    Settings.remove_zip(zip)
    remove_zip
end

#display_5_day(zip) ⇒ Object



30
31
32
33
# File 'lib/concerns/menus.rb', line 30

def display_5_day(zip)
    WeatherCLI::FiveDay.display(zip)
    choose_forecast(zip)
end

#display_hourly(zip) ⇒ Object



40
41
42
43
# File 'lib/concerns/menus.rb', line 40

def display_hourly(zip)
    WeatherCLI::Hourly.display(zip)
    choose_forecast(zip)
end

#display_single_detail(zip) ⇒ Object



35
36
37
38
# File 'lib/concerns/menus.rb', line 35

def display_single_detail(zip)
    WeatherCLI::SingleDay.display(zip)
    choose_forecast(zip)
end


11
12
13
14
15
16
17
18
19
20
# File 'lib/concerns/menus.rb', line 11

def main_menu
    zips = Settings.zip_codes
    entries = []
    zips.each do |zip|
        entries << GemMenu::Entry.new(zip, method(:choose_forecast), optional_args = {:parameters => zip})
    end
    entries << GemMenu::Entry.new("Add zip code", method(:add_zip))
    entries << GemMenu::Entry.new("Remove zip code", method(:remove_zip))
    GemMenu::Menu.new("Choose a zipcode to view forecast", entries)
end

#remove_zipObject



22
23
24
25
26
27
28
# File 'lib/concerns/menus.rb', line 22

def remove_zip
    entries = []
    Settings.zip_codes.each do |zip|
        entries << GemMenu::Entry.new(zip, method(:delete_zip), optional_args={:parameters => zip})
    end
    GemMenu::Menu.new("Select zipcode to remove", entries, optional_args={:previous_menu => method(:main_menu)})
end