weather_weasel 0.1.0

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.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_weasel.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Duncan Miller
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # WeatherWeasel
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'weather_weasel'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install weather_weasel
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,17 @@
1
+ require "httparty"
2
+ require "json"
3
+ require "weather_weasel/version"
4
+ require "weather_weasel/client"
5
+ require "weather_weasel/location"
6
+ require "weather_weasel/forecast"
7
+ require "weather_weasel/almanac"
8
+ require "weather_weasel/current_hurricane"
9
+ require "weather_weasel/conditions"
10
+
11
+
12
+ module WeatherWeasel
13
+ # portland = Location.new("Portland", "OR")
14
+ # puts portland.high
15
+ end
16
+
17
+
@@ -0,0 +1,15 @@
1
+ module WeatherWeasel
2
+ class Almanac
3
+
4
+ def initialize(city, state, tempature_format, client)
5
+ @city = city
6
+ @state = state
7
+ @tempature_format = tempature_format
8
+ @client = client
9
+ end
10
+
11
+ def raw_data
12
+ @data ||= @client.parse_url("almanac/q/#{@state}/#{@city}.json")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module WeatherWeasel
2
+ class Client
3
+
4
+ def initialize
5
+ @api_key = ENV["WUNDERGROUND_API_KEY"]
6
+ unless @api_key
7
+ raise "no api key defined in environment variables"
8
+ end
9
+ end
10
+
11
+ def parse_url(url)
12
+ response_body = HTTParty.get("http://api.wunderground.com/api/#{@api_key}/#{url}").body
13
+ JSON.parse(response_body)
14
+ end
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,15 @@
1
+ module WeatherWeasel
2
+ class Conditions
3
+
4
+ def initialize(city, state, temperature_format, client)
5
+ @city = city
6
+ @state = state
7
+ @temperature_format = temperature_format
8
+ @client = client
9
+ end
10
+
11
+ def raw_data
12
+ @data ||= @client.parse_url("conditions/q/#{@state}/#{@city}.json")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module WeatherWeasel
2
+ class CurrentHurricane
3
+
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def raw_data
9
+ @data ||= @client.parse_url("currenthurricane/view.json")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,140 @@
1
+ module WeatherWeasel
2
+ class Forecast
3
+ attr_accessor :temperature_format, :rain_format
4
+
5
+ def initialize(city, state, client)
6
+ @city = city
7
+ @state = state
8
+ @client = client
9
+ end
10
+
11
+ def raw_data
12
+ @data ||= @client.parse_url("forecast/q/#{@state}/#{@city}.json")
13
+ end
14
+
15
+ def forecast_days
16
+ raw_data["forecast"]["simpleforecast"]["forecastday"]
17
+ end
18
+
19
+ def set_scale(scale)
20
+ if scale == "imperial"
21
+ @temperature_format = "fahrenheit"
22
+ @wind_format = "mph"
23
+ @snow_format = "in"
24
+ @rain_format = "in"
25
+ else
26
+ @temperature_format = "celsius"
27
+ @wind_format = "kph"
28
+ @snow_fomrat = "cm"
29
+ @rain_format = "mm"
30
+ end
31
+ end
32
+
33
+ #Highs and lows methods
34
+ def high(scale)
35
+ all_highs(scale).max
36
+ end
37
+
38
+ def day_high(day_index, format = @rain_format)
39
+ all_highs(format)[day_index]
40
+ end
41
+
42
+ def low(scale)
43
+ all_lows(scale).min
44
+ end
45
+
46
+ def all_lows(scale)
47
+ set_scale(scale)
48
+ forecast_days.collect do |day|
49
+ day["low"][@temperature_format].to_i
50
+ end
51
+ end
52
+
53
+ def all_highs(scale)
54
+ set_scale(scale)
55
+ forecast_days.collect do |day|
56
+ day["high"][@temperature_format].to_i
57
+ end
58
+ end
59
+
60
+ #wind methods
61
+ def max_wind(scale)
62
+ all_max_wind(scale).max
63
+ end
64
+
65
+ def all_max_wind(scale)
66
+ set_scale(scale)
67
+ forecast_days.collect do |day|
68
+ day["maxwind"][@wind_format]
69
+ end
70
+ end
71
+
72
+ #snow methods
73
+ def all_snow_day(scale)
74
+ set_scale(scale)
75
+ forecast_days.collect do |day|
76
+ day["snow_day"][@snow_format]
77
+ end
78
+ end
79
+
80
+ def highest_snow_day(scale)
81
+ all_snow_day(scale).max
82
+ end
83
+
84
+ def snow_day(day_index, scale)
85
+ all_snow_day(scale)[day_index]
86
+ end
87
+
88
+ def all_snow_night(scale)
89
+ set_scale(scale)
90
+ forecast_days.collect do |day|
91
+ day["snow_night"][@snow_format]
92
+ end
93
+ end
94
+
95
+ def all_snow_allday(scale)
96
+ set_scale(scale)
97
+ forecast_days.collect do |day|
98
+ day["snow_allday"][@snow_format]
99
+ end
100
+ end
101
+
102
+ #Forecast Condition methods
103
+ def forecast_condition(day_index)
104
+ forecast_conditions[day_index]
105
+ end
106
+
107
+ def forecast_conditions
108
+ forecast_days.collect do |day|
109
+ day["conditions"]
110
+ end
111
+ end
112
+
113
+ #QPF Methods
114
+ def qpf_alldays(scale)
115
+ set_scale(scale)
116
+ forecast_days.collect do |day|
117
+ day["qpf_allday"][@rain_format]
118
+ end
119
+ end
120
+
121
+ #Skyicon Methods
122
+ def skyicon(day_index = 0)
123
+ skyicons[day_index]
124
+ end
125
+
126
+ def skyicons
127
+ forecast_days.collect do |day|
128
+ day["skyicon"]
129
+ end
130
+ end
131
+
132
+ #POPs methods
133
+ def pops
134
+ forecast_days.collect do |day|
135
+ day["pop"]
136
+ end
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,130 @@
1
+ module WeatherWeasel
2
+ class Location
3
+
4
+ def initialize(city, state, scale = "imperial")
5
+ @city = city
6
+ @state = state
7
+ @scale = scale
8
+ @client = Client.new
9
+ end
10
+
11
+ #current Hurricane Method
12
+ def current_hurricane
13
+ @current_hurricane ||= CurrentHurricane.new(@client)
14
+ end
15
+
16
+ def current_hurricane_raw
17
+ current_hurricane.raw_data
18
+ end
19
+
20
+ #Almanac method
21
+ def almanac_raw
22
+ almanac.raw_data
23
+ end
24
+
25
+ def almanac
26
+ @almanac ||= Almanac.new(@city, @state, @scale, @client)
27
+ end
28
+
29
+ #Condition (specific location method)
30
+ def conditions
31
+ @conditions ||= Conditions.new(@city, @state, @scale, @client)
32
+ end
33
+
34
+ #Forecast_conditions Methods
35
+ def forecast_conditions
36
+ forecast.forecast_conditions
37
+ end
38
+
39
+ def forecast_condition(day_index)
40
+ forecast.forecast_condition(day_index)
41
+ end
42
+
43
+ #POPS Methods
44
+ def pop(day_index)
45
+ forecast.pops[day_index]
46
+ end
47
+
48
+ def pops
49
+ forecast.pops
50
+ end
51
+
52
+ #QPF Methods
53
+ def qpf_alldays(scale = @scale)
54
+ forecast.qpf_alldays(scale)
55
+ end
56
+
57
+ #Forecast Methods
58
+ def forecast
59
+ @forecast ||= Forecast.new(@city, @state, @client)
60
+ end
61
+
62
+ def forecast_raw
63
+ forecast.raw_data
64
+ end
65
+
66
+ #Skyicon Methods
67
+ def skyicons
68
+ forecast.skyicons
69
+ end
70
+
71
+ def skyicon(day_index)
72
+ forecast.skyicon(day_index)
73
+ end
74
+
75
+ #Temperature Methods
76
+ def high(scale = @scale)
77
+ forecast.high(scale)
78
+ end
79
+
80
+ def day_high(day_index, scale = @scale)
81
+ forecast.all_highs(day_index, format)
82
+ end
83
+
84
+ def low(scale = @scale)
85
+ forecast.low(scale)
86
+ end
87
+
88
+ def all_highs(scale = @scale)
89
+ forecast.all_highs(scale)
90
+ end
91
+
92
+ def all_lows(scale = @scale)
93
+ forecast.all_lows(scale)
94
+ end
95
+
96
+ def all_max_wind(scale = @scale)
97
+ forecast.all_max_wind(scale)
98
+ end
99
+
100
+ def max_wind(scale = @scale)
101
+ forecast.max_wind(scale)
102
+ end
103
+
104
+ def all_snow_day(scale = @scale)
105
+ forecast.all_snow_day(scale)
106
+ end
107
+
108
+ def snow_day(day, scale = @scale)
109
+ forecast.snow_day(day, scale)
110
+ end
111
+
112
+ def highest_snow_day(scale = @scale)
113
+ forecast.highest_snow_day(scale)
114
+ end
115
+
116
+ def all_snow_night(scale = @scale)
117
+ forecast.snow_night(scale)
118
+ end
119
+
120
+ def all_snow_allday(scale = @scale)
121
+ forecast.all_snow_allday(scale)
122
+ end
123
+
124
+ end
125
+ end
126
+
127
+
128
+
129
+ #portland = Location.new("Portland", "OR", "metric")
130
+ # portland.forecast("metric")
@@ -0,0 +1,3 @@
1
+ module WeatherWeasel
2
+ VERSION = "0.1.0"
3
+ end