Class: Weather::ForecastCli
- Inherits:
-
Object
- Object
- Weather::ForecastCli
show all
- Includes:
- RubyFiglet
- Defined in:
- lib/forecastcli.rb
Defined Under Namespace
Classes: Error, WeatherError
Constant Summary
collapse
- APP_ID =
ENV['API_KEY']
Instance Method Summary
collapse
Instance Method Details
#additional_options ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/forecastcli.rb', line 59
def additional_options
system('cls') || system('clear')
case @selection
when 'Next-Day-Forecast'
@@counter = 1
specific_request
additional_options
when 'Next-2-Days-Forecast'
@@counter = 2
specific_request
additional_options
when 'Next-3-Days-Forecast'
@@counter = 3
specific_request
additional_options
when 'Next-4-Days-Forecast'
@@counter = 4
specific_request
additional_options
when 'Check-Another-Area'
Weather::Forecast.erase
system('cls') || system('clear')
instructions
else
Weather::Forecast.erase
system('cls') || system('clear')
goodbye
exit
end
end
|
#goodbye ⇒ Object
102
103
104
105
|
# File 'lib/forecastcli.rb', line 102
def goodbye
puts 'Thanks "for" visiting!'.colorize(:blue)
puts 'Enjoy the weather until next time :)'.colorize(:blue)
end
|
#instructions ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/forecastcli.rb', line 31
def instructions
puts 'Enter your five digit zipcode to get started or "exit" to quit:'.colorize(:blue)
zipcode = gets.chomp.downcase
while zipcode != 'exit'
if zipcode[/[0-9]+/] == zipcode && zipcode.length == 5
system('cls') || system('clear')
Weather::ForecastApi.fetch(zipcode)
puts "This is the 24 HRS forecast for #{Weather::Forecast.all.first.location}:".colorize(:blue)
puts ''
Weather::Forecast.day_display
line_break
puts ''
@options = %w(Exit Check-Another-Area Next-Day-Forecast Next-2-Days-Forecast Next-3-Days-Forecast Next-4-Days-Forecast)
additional_options
else
begin
raise Error
rescue Error => exception
puts exception.message
end
instructions
end
end
system('cls') || system('clear')
goodbye
end
|
#line_break ⇒ Object
98
99
100
|
# File 'lib/forecastcli.rb', line 98
def line_break
puts '============================================================================================================='.colorize(:white)
end
|
94
95
96
|
# File 'lib/forecastcli.rb', line 94
def
@selection = $prompt.select("What would you like to do next?".colorize(:green), @options)
end
|
#specific_request ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/forecastcli.rb', line 107
def specific_request
if Weather::Forecast.all.empty?
begin
raise WeatherError
rescue WeatherError => exception
puts exception.message
end
@options = %w(Exit Check-Another-Area)
additional_options
else
@@counter.times do
Weather::Forecast.day_display unless Weather::Forecast.all.empty?
@options.pop
end
puts 'You have now viewed the maximum five days forecast.'.colorize(:red) if @options.size == 2
end
line_break
end
|
#start ⇒ Object
6
7
8
9
|
# File 'lib/forecastcli.rb', line 6
def start
self.welcome
self.instructions
end
|
#welcome ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/forecastcli.rb', line 11
def welcome
puts Figlet.new('WEATHER-FORECAST').to_s.colorize(:red)
puts ''
puts ''
puts 'Welcome to your forecast!'.colorize(:blue)
puts ''
puts 'This is your personalized weather assistant that allows you
to get daily weather information by zipcode.'
line_break
puts ''
puts 'Instructions'.colorize(:red)
puts ''
puts 'Follow instruction bellow'
puts 'Enter zipcode to get weather detail'
puts "Type 'exit' to quit".colorize(:blue)
self.line_break
puts ''
end
|