simple_forecast 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/forecast +8 -9
- data/config/cli.rb +7 -1
- data/config/environment.rb +1 -0
- data/lib/models/cli_router.rb +33 -0
- data/lib/models/forecast.rb +62 -11
- data/lib/weather_data.rb +18 -19
- data/simple_forecast.gemspec +4 -4
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a55167aba9bc0078e3ca220ca45251b5e141e04b
|
4
|
+
data.tar.gz: 9453f1260b7b6be4783c1aabe2b90a6f51ad90e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d78b42052ff134d30a0ff8d8ac8cf716f624526f7db29505cedf856caf28ebf2ad6d3fb884e8d6d5e99abe337c40272d3e0a0d8f642c8e82a5b2cde7cb20145a
|
7
|
+
data.tar.gz: 67797b201fcb5b82da75532b3c944f3f98b86f94f65ce997f7652330fe53cf70fa0826581c2728191c7b3a64abb7e524c15b44159ddf221143b74fba3181fb17
|
data/bin/forecast
CHANGED
@@ -4,12 +4,11 @@
|
|
4
4
|
|
5
5
|
require_relative '../config/environment.rb'
|
6
6
|
|
7
|
-
cli =
|
8
|
-
|
9
|
-
if ARGV.empty?
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
7
|
+
cli = CLIRouter.new(ARGV)
|
8
|
+
|
9
|
+
# if ARGV.empty?
|
10
|
+
# # this should return the same as 'forecast today'
|
11
|
+
# ARGV[0] = "help"
|
12
|
+
# end
|
13
|
+
|
14
|
+
cli.commands
|
data/config/cli.rb
CHANGED
@@ -43,8 +43,14 @@ class CLI
|
|
43
43
|
|
44
44
|
def tomorrow
|
45
45
|
get_data = Forecast.new(WeatherData.new)
|
46
|
-
puts get_data.
|
46
|
+
puts get_data.tomorrow
|
47
47
|
# exit
|
48
48
|
end
|
49
49
|
|
50
|
+
def today
|
51
|
+
get_data = Forecast.new(WeatherData.new)
|
52
|
+
puts get_data.today
|
53
|
+
end
|
54
|
+
|
55
|
+
|
50
56
|
end
|
data/config/environment.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
class CLIRouter
|
2
|
+
|
3
|
+
attr_reader :weather_forecast, :args
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@weather_forecast = Forecast.new(WeatherData.new)
|
7
|
+
@args = args # in fact this is ARGV
|
8
|
+
end
|
9
|
+
|
10
|
+
def help
|
11
|
+
weather_forecast.today
|
12
|
+
puts "if you'd like a different forecast try something like 'forecast tomorrow'"
|
13
|
+
end
|
14
|
+
|
15
|
+
def commands
|
16
|
+
if args.length == 1
|
17
|
+
puts weather_forecast.send(self.args[0])
|
18
|
+
elsif args.length == 0
|
19
|
+
help
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# def this_weekend
|
24
|
+
# puts weather_data.this_weekend
|
25
|
+
|
26
|
+
# end
|
27
|
+
|
28
|
+
# def next_week
|
29
|
+
# puts weather_data.next_week
|
30
|
+
# end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
data/lib/models/forecast.rb
CHANGED
@@ -1,25 +1,76 @@
|
|
1
1
|
class Forecast
|
2
2
|
|
3
|
-
attr_accessor :today_temp, :yesterday_temp
|
3
|
+
attr_accessor :today_temp, :yesterday_temp, :tomorrow_temp, :weather_data
|
4
4
|
|
5
5
|
def initialize(weather_data_object)
|
6
|
+
@weather_data = weather_data_object
|
6
7
|
|
7
|
-
@today_temp =
|
8
|
-
@
|
8
|
+
@today_temp = self.weather_data.temp_today
|
9
|
+
@tomorrow_temp = self.weather_data.temp_tomorrow
|
10
|
+
# @this_weekend = self.avg_temp_this_weekend
|
11
|
+
# @next_week = self.avg_temp_next_week
|
9
12
|
end
|
10
13
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def today
|
15
|
+
puts "hmm, interesting!"
|
16
|
+
@yesterday_temp = self.weather_data.temp_yesterday
|
17
|
+
compare(today_temp, yesterday_temp) + "yesterday"
|
18
|
+
end
|
19
|
+
|
20
|
+
def tomorrow
|
21
|
+
compare(tomorrow_temp, today_temp) + "today"
|
22
|
+
end
|
23
|
+
|
24
|
+
def avg_temp_this_weekend
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def avg_temp_next_weekend
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def this_weekend
|
33
|
+
# compare(this_week_avg_temp?, temp_for_upcoming_weekend)
|
34
|
+
end
|
35
|
+
|
36
|
+
def next_week
|
37
|
+
# compare(this_week_avg, next_week_avg)
|
38
|
+
end
|
39
|
+
|
40
|
+
def compare(temp1, temp2)
|
41
|
+
diff = temp1-temp2
|
42
|
+
|
43
|
+
case diff.abs
|
44
|
+
when (1..2)
|
45
|
+
temp1 = temp2
|
46
|
+
when (3..7)
|
47
|
+
mod = "slightly "
|
48
|
+
when (7..12)
|
49
|
+
mod = "somewhat "
|
50
|
+
when (12..30)
|
51
|
+
mod = "much "
|
18
52
|
else
|
19
|
-
|
53
|
+
mod = ''
|
54
|
+
end
|
55
|
+
|
56
|
+
if temp1 == temp2
|
57
|
+
"pretty much the same as "
|
58
|
+
elsif temp1 < temp2
|
59
|
+
mod + "colder than "
|
60
|
+
else
|
61
|
+
mod + "warmer than "
|
20
62
|
end
|
21
63
|
end
|
22
64
|
|
65
|
+
# categorization
|
66
|
+
# "same"
|
67
|
+
# "colder than"
|
68
|
+
# "warmer than"
|
69
|
+
|
70
|
+
# compared objects
|
71
|
+
# "yesterday"
|
72
|
+
# "today"
|
73
|
+
# "tomorrow"
|
23
74
|
|
24
75
|
end
|
25
76
|
|
data/lib/weather_data.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
1
|
class WeatherData
|
2
2
|
|
3
|
-
attr_accessor :yesterday_data, :today_data
|
3
|
+
attr_accessor :yesterday_data, :today_data, :lat, :long
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
NYC = [40.714623, -74.006605]
|
6
|
+
NYC_LAT = NYC[0]
|
7
|
+
NYC_LONG = NYC[1]
|
7
8
|
|
8
|
-
def initialize(lat = NYC_LAT,
|
9
|
-
|
10
|
-
@
|
11
|
-
|
12
|
-
@
|
13
|
-
print ".\n "
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def time_yesterday
|
20
|
-
Time.now.to_i - 86400
|
9
|
+
def initialize(lat = NYC_LAT, long = NYC_LONG)
|
10
|
+
@lat = lat
|
11
|
+
@long = long
|
12
|
+
puts "checking my instruments"
|
13
|
+
@today_data = ForecastIO.forecast(self.lat, self.long, time: Time.now.to_i)
|
21
14
|
end
|
22
15
|
|
23
|
-
|
24
|
-
|
16
|
+
def temp_yesterday
|
17
|
+
@yesterday_data = ForecastIO.forecast(self.lat, self.long, time: time_yesterday)
|
25
18
|
self.yesterday_data["currently"]["temperature"]
|
26
19
|
end
|
27
20
|
|
28
|
-
def
|
21
|
+
def temp_today
|
29
22
|
self.today_data["currently"]["temperature"]
|
30
23
|
end
|
31
24
|
|
25
|
+
def temp_tomorrow
|
26
|
+
self.today_data["hourly"]["data"][23]["temperature"]
|
27
|
+
end
|
32
28
|
|
29
|
+
def time_yesterday
|
30
|
+
Time.now.to_i - 86400
|
31
|
+
end
|
33
32
|
|
34
33
|
end
|
data/simple_forecast.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'simple_forecast'
|
3
|
-
s.executables
|
4
|
-
s.version = "0.0.
|
3
|
+
s.executables << 'forecast'
|
4
|
+
s.version = "0.0.2"
|
5
5
|
s.date = "2013-10-19"
|
6
6
|
s.summary = "A simple weather forecaster"
|
7
|
-
s.description = "A
|
7
|
+
s.description = "A weather forecast relative to current conditions where you are. Currently only works for New York, NY."
|
8
8
|
s.authors = ["Anders Ramsay", "Joe O'Conor"]
|
9
9
|
s.email = ["andersr@gmail.com", "joe.oconor@gmail.com"]
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.homepage = 'https://github.com/andersr/simple_weather'
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.require_path = '.'
|
14
|
-
s.add_runtime_dependency 'forecast_io' >=
|
14
|
+
s.add_runtime_dependency 'forecast_io', ['>= 2.0.0']
|
15
15
|
s.post_install_message = <<-MSG
|
16
16
|
Thanks for installing Simple Forecast. Enter 'forecast' to get the current forecast or something like 'forecast tomorrow' for a different forecast.
|
17
17
|
MSG
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_forecast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anders Ramsay
|
@@ -12,20 +12,21 @@ cert_chain: []
|
|
12
12
|
date: 2013-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: forecast_io
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
description: A
|
27
|
+
version: 2.0.0
|
28
|
+
description: A weather forecast relative to current conditions where you are. Currently
|
29
|
+
only works for New York, NY.
|
29
30
|
email:
|
30
31
|
- andersr@gmail.com
|
31
32
|
- joe.oconor@gmail.com
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- config/cli.rb
|
44
45
|
- config/environment.rb
|
45
46
|
- data/forecast_io_sample.rb
|
47
|
+
- lib/models/cli_router.rb
|
46
48
|
- lib/models/forecast.rb
|
47
49
|
- lib/models/scraper.rb
|
48
50
|
- lib/weather_data.rb
|