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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f75d7c0552ace3efb79aef082d5e4ed1ea4e8643
4
- data.tar.gz: f84c79f3632a26f1d013a6f9060a85b3a2108f1c
3
+ metadata.gz: a55167aba9bc0078e3ca220ca45251b5e141e04b
4
+ data.tar.gz: 9453f1260b7b6be4783c1aabe2b90a6f51ad90e4
5
5
  SHA512:
6
- metadata.gz: 07fd89d3acd2384fa273c04c83e82a46032facafed4019daba67cdbe0a822070686711b561b88035ac87942af5a0ff259e8b36a7963f90145d05f5724cdd3374
7
- data.tar.gz: 68c4417b2d25c56b389bbc82b22bc7d91b3516dff8696b31e1e981c52b35fde380a87e9d366c11a02bc075509de844a9c67e56b0a62be1c3ace4c7667b9dd19a
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 = CLI.new
8
-
9
- if ARGV.empty?
10
- # this should return the same as 'forecast today'
11
- ARGV[0] = "help"
12
- cli.send(ARGV[0])
13
- else
14
- cli.send(ARGV[0])
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.generate_forecast
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
@@ -7,3 +7,4 @@ require_relative '../config/cli'
7
7
  require_relative '../lib/models/scraper'
8
8
  require_relative '../lib/models/forecast'
9
9
  require_relative '../lib/weather_data'
10
+ require_relative '../lib/models/cli_router'
@@ -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
+
@@ -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 = weather_data_object.get_temp_today
8
- @yesterday_temp = weather_data_object.get_temp_yesterday
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 generate_forecast
12
- # determine whether today temp is higher, lower or the same as yesterday
13
- # return a string based on that result
14
- if self.today_temp == self.yesterday_temp
15
- "same as yesterday"
16
- elsif self.today_temp < self.yesterday_temp
17
- "colder than yesterday"
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
- "warmer than yesterday"
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
- NYC_LAT = 40.714623
6
- NYC_LON = -74.006605
5
+ NYC = [40.714623, -74.006605]
6
+ NYC_LAT = NYC[0]
7
+ NYC_LONG = NYC[1]
7
8
 
8
- def initialize(lat = NYC_LAT, lon = NYC_LON)
9
- print "checking the weather."
10
- @today_data = ForecastIO.forecast(lat, lon, time: Time.now.to_i)
11
- print " . "
12
- @yesterday_data = ForecastIO.forecast(lat, lon, time: time_yesterday)
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
- def get_temp_yesterday
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 get_temp_today
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
@@ -1,17 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'simple_forecast'
3
- s.executables << 'forecast'
4
- s.version = "0.0.1"
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 simple weather forecaster"
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' >= '2.0.0'
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.1
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: 'true'
15
+ name: forecast_io
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
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: '0'
28
- description: A simple weather forecaster
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