sunweather 0.3.1 → 0.3.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/README.rdoc +21 -3
- data/VERSION +1 -1
- data/lib/data.rb +86 -0
- data/lib/runner.rb +6 -8
- data/meditation +1905 -0
- data/spec/data_spec.rb +73 -0
- data/sunweather.gemspec +5 -6
- metadata +5 -6
- data/lib/sun.rb +0 -60
- data/lib/weather.rb +0 -39
- data/spec/sun_spec.rb +0 -50
- data/spec/weather_spec.rb +0 -33
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative "../lib/geo"
|
2
|
+
require_relative "../lib/data"
|
3
|
+
|
4
|
+
describe Sunweather::Data, "after initializing with geocoordinates from default Geo object" do
|
5
|
+
let(:geo) { Sunweather::Geo.new }
|
6
|
+
let(:data) { Sunweather::Data.new(geo.lat, geo.lng) }
|
7
|
+
|
8
|
+
it "contains the required data from World Weather Online, Wunderground and Earthtools" do
|
9
|
+
expect(data.data_astro_conditions).not_to be_nil
|
10
|
+
expect(data.data_astro_conditions["current_observation"][0]["observation_epoch"][0].to_i).to be_within(7*86400).of(Time.now.to_i)
|
11
|
+
expect(Float(data.data_astro_conditions["current_observation"][0]["temp_c"][0])).to be_within(100).of(0)
|
12
|
+
expect(Float(data.data_astro_conditions["current_observation"][0]["feelslike_c"][0])).to be_within(100).of(0)
|
13
|
+
expect(data.data_astro_conditions["current_observation"][0]["weather"][0]).to_not be_empty
|
14
|
+
expect(data.data_astro_conditions["current_observation"][0]["wind_string"][0]).to_not be_empty
|
15
|
+
expect(data.data_astro_conditions["current_observation"][0]["wind_dir"][0]).to_not be_empty
|
16
|
+
expect(data.data_forecast).not_to be_nil
|
17
|
+
expect(data.data_forecast["weather"][0]["tempMinC"][0].to_i).to be_within(100).of(0)
|
18
|
+
expect(data.data_forecast["weather"][0]["tempMaxC"][0].to_i).to be_within(100).of(0)
|
19
|
+
expect(data.data_forecast["weather"][0]["weatherDesc"][0]).to_not be_empty
|
20
|
+
expect(data.data_forecast["weather"][0]["windspeedKmph"][0].to_i).to be_within(100).of(100)
|
21
|
+
expect(data.data_forecast["weather"][0]["winddir16Point"][0]).to_not be_empty
|
22
|
+
expect(data.data_forecast["weather"][4]["tempMinC"][0].to_i).to be_within(100).of(0)
|
23
|
+
expect(data.data_forecast["weather"][4]["tempMaxC"][0].to_i).to be_within(100).of(0)
|
24
|
+
expect(data.data_forecast["weather"][4]["weatherDesc"][0]).to_not be_empty
|
25
|
+
expect(data.data_forecast["weather"][4]["windspeedKmph"][0].to_i).to be_within(100).of(100)
|
26
|
+
expect(data.data_forecast["weather"][4]["winddir16Point"][0]).to_not be_empty
|
27
|
+
expect(data.temperature).to be_within(100).of(0)
|
28
|
+
expect(data.feels_like).to be_within(100).of(0)
|
29
|
+
expect(data.observation_time.min).to be_within(30).of(30)
|
30
|
+
expect(data.conditions).to_not be_empty
|
31
|
+
expect(data.wind_speed).to_not be_empty
|
32
|
+
expect(data.data_astro_conditions).not_to be_nil
|
33
|
+
expect(data.data_astro_conditions["sun_phase"][0]["sunrise"][0]["hour"][0].to_i).to be_within(12).of(12)
|
34
|
+
expect(data.data_astro_conditions["sun_phase"][0]["sunrise"][0]["minute"][0].to_i).to be_within(30).of(30)
|
35
|
+
expect(data.data_astro_conditions["sun_phase"][0]["sunset"][0]["hour"][0].to_i).to be_within(12).of(12)
|
36
|
+
expect(data.data_astro_conditions["sun_phase"][0]["sunset"][0]["minute"][0].to_i).to be_within(30).of(30)
|
37
|
+
expect(data.sunrise.min).to be_within(30).of(30)
|
38
|
+
expect(data.sunrise.hour).to be_within(12).of(12)
|
39
|
+
expect(data.sunset.min).to be_within(30).of(30)
|
40
|
+
expect(data.sunset.hour).to be_within(12).of(12)
|
41
|
+
expect(data.data_twilight).not_to be_nil
|
42
|
+
expect(DateTime.parse(data.data_twilight["morning"][0]["twilight"][0]["civil"][0]).sec).to be_within(30).of(30)
|
43
|
+
expect(DateTime.parse(data.data_twilight["morning"][0]["twilight"][0]["civil"][0]).min).to be_within(30).of(30)
|
44
|
+
expect(DateTime.parse(data.data_twilight["morning"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
|
45
|
+
expect(DateTime.parse(data.data_twilight["evening"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
|
46
|
+
expect(DateTime.parse(data.data_twilight["morning"][0]["sunrise"][0]).hour).to be_within(30).of(30)
|
47
|
+
expect(DateTime.parse(data.data_twilight["evening"][0]["sunset"][0]).hour).to be_within(30).of(30)
|
48
|
+
expect(data.sunrise_earthtools.sec).to be_within(30).of(30)
|
49
|
+
expect(data.sunrise_earthtools.min).to be_within(30).of(30)
|
50
|
+
expect(data.sunrise_earthtools.hour).to be_within(12).of(12)
|
51
|
+
expect(data.sunset_earthtools.sec).to be_within(30).of(30)
|
52
|
+
expect(data.sunset_earthtools.min).to be_within(30).of(30)
|
53
|
+
expect(data.sunset_earthtools.hour).to be_within(12).of(12)
|
54
|
+
expect(data.start_of_dawn_earthtools.sec).to be_within(30).of(30)
|
55
|
+
expect(data.start_of_dawn_earthtools.min).to be_within(30).of(30)
|
56
|
+
expect(data.start_of_dawn_earthtools.hour).to be_within(12).of(12)
|
57
|
+
expect(data.end_of_dusk_earthtools.sec).to be_within(30).of(30)
|
58
|
+
expect(data.end_of_dusk_earthtools.min).to be_within(30).of(30)
|
59
|
+
expect(data.end_of_dusk_earthtools.hour).to be_within(12).of(12)
|
60
|
+
expect(data.start_of_dawn.sec).to be_within(30).of(30)
|
61
|
+
expect(data.start_of_dawn.min).to be_within(30).of(30)
|
62
|
+
expect(data.start_of_dawn.hour).to be_within(12).of(12)
|
63
|
+
expect(data.end_of_dusk.sec).to be_within(30).of(30)
|
64
|
+
expect(data.end_of_dusk.min).to be_within(30).of(30)
|
65
|
+
expect(data.end_of_dusk.hour).to be_within(12).of(12)
|
66
|
+
expect(data.dawn_length.sec).to be_within(30).of(30)
|
67
|
+
expect(data.dawn_length.min).to be_within(30).of(30)
|
68
|
+
expect(data.dawn_length.hour).to be_within(12).of(12)
|
69
|
+
expect(data.dusk_length.sec).to be_within(30).of(30)
|
70
|
+
expect(data.dusk_length.min).to be_within(30).of(30)
|
71
|
+
expect(data.dusk_length.hour).to be_within(12).of(12)
|
72
|
+
end
|
73
|
+
end
|
data/sunweather.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sunweather"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tobi Frank"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-12-01"
|
13
13
|
s.description = "Provides sunrise/sunset and weather info for given address."
|
14
14
|
s.email = "tobifrank38@gmail.com"
|
15
15
|
s.executables = ["sunweather"]
|
@@ -27,14 +27,13 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"bin/sunweather",
|
30
|
+
"lib/data.rb",
|
30
31
|
"lib/geo.rb",
|
31
32
|
"lib/runner.rb",
|
32
|
-
"
|
33
|
-
"
|
33
|
+
"meditation",
|
34
|
+
"spec/data_spec.rb",
|
34
35
|
"spec/geo_spec.rb",
|
35
36
|
"spec/spec_helper.rb",
|
36
|
-
"spec/sun_spec.rb",
|
37
|
-
"spec/weather_spec.rb",
|
38
37
|
"sunweather.gemspec",
|
39
38
|
"temp"
|
40
39
|
]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunweather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobi Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -168,14 +168,13 @@ files:
|
|
168
168
|
- Rakefile
|
169
169
|
- VERSION
|
170
170
|
- bin/sunweather
|
171
|
+
- lib/data.rb
|
171
172
|
- lib/geo.rb
|
172
173
|
- lib/runner.rb
|
173
|
-
-
|
174
|
-
-
|
174
|
+
- meditation
|
175
|
+
- spec/data_spec.rb
|
175
176
|
- spec/geo_spec.rb
|
176
177
|
- spec/spec_helper.rb
|
177
|
-
- spec/sun_spec.rb
|
178
|
-
- spec/weather_spec.rb
|
179
178
|
- sunweather.gemspec
|
180
179
|
- temp
|
181
180
|
homepage: http://github.com/tobifrank/sunweather
|
data/lib/sun.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'xmlsimple'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'date'
|
4
|
-
|
5
|
-
module Sunweather
|
6
|
-
class Sun
|
7
|
-
attr_reader :data_sunrise_sunset, :data_twilight
|
8
|
-
|
9
|
-
def initialize lat, lng
|
10
|
-
file = open("http://api.wunderground.com/api/#{ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]}/astronomy/q/#{lat},#{lng}.xml")
|
11
|
-
@data_sunrise_sunset = XmlSimple.xml_in(file)
|
12
|
-
file = open("http://www.earthtools.org/sun/#{lat}/#{lng}/#{Time.now.mday}/#{Time.now.mon}/99/0")
|
13
|
-
@data_twilight = XmlSimple.xml_in(file)
|
14
|
-
end
|
15
|
-
|
16
|
-
def sunrise
|
17
|
-
Time.new(1970,1,1,self.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["hour"][0],self.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["minute"][0])
|
18
|
-
end
|
19
|
-
|
20
|
-
def sunset
|
21
|
-
Time.new(1970,1,1,self.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["hour"][0],self.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["minute"][0])
|
22
|
-
end
|
23
|
-
|
24
|
-
def sunrise_earthtools
|
25
|
-
DateTime.parse(self.data_twilight["morning"][0]["sunrise"][0]).to_time
|
26
|
-
end
|
27
|
-
|
28
|
-
def sunset_earthtools
|
29
|
-
DateTime.parse(self.data_twilight["evening"][0]["sunset"][0]).to_time
|
30
|
-
end
|
31
|
-
|
32
|
-
def start_of_dawn_earthtools
|
33
|
-
DateTime.parse(self.data_twilight["morning"][0]["twilight"][0]["civil"][0]).to_time
|
34
|
-
end
|
35
|
-
|
36
|
-
def end_of_dusk_earthtools
|
37
|
-
DateTime.parse(self.data_twilight["evening"][0]["twilight"][0]["civil"][0]).to_time
|
38
|
-
end
|
39
|
-
|
40
|
-
def dawn_length
|
41
|
-
Time.at(self.sunrise_earthtools - self.start_of_dawn_earthtools)
|
42
|
-
end
|
43
|
-
|
44
|
-
def dusk_length
|
45
|
-
Time.at(self.end_of_dusk_earthtools - self.sunset_earthtools)
|
46
|
-
end
|
47
|
-
|
48
|
-
def start_of_dawn
|
49
|
-
Time.at(self.sunrise - self.dawn_length)
|
50
|
-
end
|
51
|
-
|
52
|
-
def end_of_dusk
|
53
|
-
Time.at(self.sunset.to_i + self.dawn_length.to_i)
|
54
|
-
end
|
55
|
-
|
56
|
-
def hours_minutes time
|
57
|
-
"#{time.hour}:#{time.minute+time.second/30}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/weather.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'xmlsimple'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
module Sunweather
|
5
|
-
class Weather
|
6
|
-
attr_reader :data_current, :data_forecast
|
7
|
-
|
8
|
-
def initialize lat, lng
|
9
|
-
file = open("http://api.wunderground.com/api/#{ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]}/conditions/q/#{lat},#{lng}.xml")
|
10
|
-
@data_current = XmlSimple.xml_in(file)
|
11
|
-
file = open("http://api.worldweatheronline.com/free/v1/weather.ashx?q=#{lat},#{lng}&format=xml&extra=localObsTime&num_of_days=5&includelocation=yes&key=#{ENV['SUNWEATHER_DEV_WWO_API']}")
|
12
|
-
@data_forecast = XmlSimple.xml_in(file)
|
13
|
-
end
|
14
|
-
|
15
|
-
def temperature
|
16
|
-
Float(self.data_current["current_observation"][0]["temp_c"][0])
|
17
|
-
end
|
18
|
-
|
19
|
-
def feels_like
|
20
|
-
Float(self.data_current["current_observation"][0]["feelslike_c"][0])
|
21
|
-
end
|
22
|
-
|
23
|
-
def observation_time
|
24
|
-
Time.at(Integer(self.data_current["current_observation"][0]["observation_epoch"][0]))
|
25
|
-
end
|
26
|
-
|
27
|
-
def conditions
|
28
|
-
self.data_current["current_observation"][0]["weather"][0]
|
29
|
-
end
|
30
|
-
|
31
|
-
def wind_speed
|
32
|
-
self.data_current["current_observation"][0]["wind_string"][0]
|
33
|
-
end
|
34
|
-
|
35
|
-
def wind_direction
|
36
|
-
self.data_current["current_observation"][0]["wind_dir"][0]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/spec/sun_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require_relative "../lib/geo"
|
2
|
-
require_relative "../lib/sun"
|
3
|
-
|
4
|
-
describe Sunweather::Sun, "after initializing with geocoordinates from default Geo object" do
|
5
|
-
let(:geo) { Sunweather::Geo.new }
|
6
|
-
let(:sun) { Sunweather::Sun.new(geo.lat, geo.lng) }
|
7
|
-
|
8
|
-
it "contains the required data from Wunderground and Earthtools" do
|
9
|
-
expect(sun.data_sunrise_sunset).not_to be_nil
|
10
|
-
expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["hour"][0])).to be_within(12).of(12)
|
11
|
-
expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["minute"][0])).to be_within(30).of(30)
|
12
|
-
expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["hour"][0])).to be_within(12).of(12)
|
13
|
-
expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["minute"][0])).to be_within(30).of(30)
|
14
|
-
expect(sun.sunrise.min).to be_within(30).of(30)
|
15
|
-
expect(sun.sunrise.hour).to be_within(12).of(12)
|
16
|
-
expect(sun.sunset.min).to be_within(30).of(30)
|
17
|
-
expect(sun.sunset.hour).to be_within(12).of(12)
|
18
|
-
expect(sun.data_twilight).not_to be_nil
|
19
|
-
expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).sec).to be_within(30).of(30)
|
20
|
-
expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).min).to be_within(30).of(30)
|
21
|
-
expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
|
22
|
-
expect(DateTime.parse(sun.data_twilight["evening"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
|
23
|
-
expect(DateTime.parse(sun.data_twilight["morning"][0]["sunrise"][0]).hour).to be_within(30).of(30)
|
24
|
-
expect(DateTime.parse(sun.data_twilight["evening"][0]["sunset"][0]).hour).to be_within(30).of(30)
|
25
|
-
expect(sun.sunrise_earthtools.sec).to be_within(30).of(30)
|
26
|
-
expect(sun.sunrise_earthtools.min).to be_within(30).of(30)
|
27
|
-
expect(sun.sunrise_earthtools.hour).to be_within(12).of(12)
|
28
|
-
expect(sun.sunset_earthtools.sec).to be_within(30).of(30)
|
29
|
-
expect(sun.sunset_earthtools.min).to be_within(30).of(30)
|
30
|
-
expect(sun.sunset_earthtools.hour).to be_within(12).of(12)
|
31
|
-
expect(sun.start_of_dawn_earthtools.sec).to be_within(30).of(30)
|
32
|
-
expect(sun.start_of_dawn_earthtools.min).to be_within(30).of(30)
|
33
|
-
expect(sun.start_of_dawn_earthtools.hour).to be_within(12).of(12)
|
34
|
-
expect(sun.end_of_dusk_earthtools.sec).to be_within(30).of(30)
|
35
|
-
expect(sun.end_of_dusk_earthtools.min).to be_within(30).of(30)
|
36
|
-
expect(sun.end_of_dusk_earthtools.hour).to be_within(12).of(12)
|
37
|
-
expect(sun.start_of_dawn.sec).to be_within(30).of(30)
|
38
|
-
expect(sun.start_of_dawn.min).to be_within(30).of(30)
|
39
|
-
expect(sun.start_of_dawn.hour).to be_within(12).of(12)
|
40
|
-
expect(sun.end_of_dusk.sec).to be_within(30).of(30)
|
41
|
-
expect(sun.end_of_dusk.min).to be_within(30).of(30)
|
42
|
-
expect(sun.end_of_dusk.hour).to be_within(12).of(12)
|
43
|
-
expect(sun.dawn_length.sec).to be_within(30).of(30)
|
44
|
-
expect(sun.dawn_length.min).to be_within(30).of(30)
|
45
|
-
expect(sun.dawn_length.hour).to be_within(12).of(12)
|
46
|
-
expect(sun.dusk_length.sec).to be_within(30).of(30)
|
47
|
-
expect(sun.dusk_length.min).to be_within(30).of(30)
|
48
|
-
expect(sun.dusk_length.hour).to be_within(12).of(12)
|
49
|
-
end
|
50
|
-
end
|
data/spec/weather_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative "../lib/geo"
|
2
|
-
require_relative "../lib/weather"
|
3
|
-
|
4
|
-
describe Sunweather::Weather, "after initializing with geocoordinates from default Geo object" do
|
5
|
-
let(:geo) { Sunweather::Geo.new }
|
6
|
-
let(:weather) { Sunweather::Weather.new(geo.lat, geo.lng) }
|
7
|
-
|
8
|
-
it "contains the required data from World Weather Online" do
|
9
|
-
expect(weather.data_current).not_to be_nil
|
10
|
-
expect(Integer(weather.data_current["current_observation"][0]["observation_epoch"][0])).to be_within(7*86400).of(Time.now.to_i)
|
11
|
-
expect(Float(weather.data_current["current_observation"][0]["temp_c"][0])).to be_within(100).of(0)
|
12
|
-
expect(Float(weather.data_current["current_observation"][0]["feelslike_c"][0])).to be_within(100).of(0)
|
13
|
-
expect(weather.data_current["current_observation"][0]["weather"][0]).to_not be_empty
|
14
|
-
expect(weather.data_current["current_observation"][0]["wind_string"][0]).to_not be_empty
|
15
|
-
expect(weather.data_current["current_observation"][0]["wind_dir"][0]).to_not be_empty
|
16
|
-
expect(weather.data_forecast).not_to be_nil
|
17
|
-
expect(Integer(weather.data_forecast["weather"][0]["tempMinC"][0])).to be_within(100).of(0)
|
18
|
-
expect(Integer(weather.data_forecast["weather"][0]["tempMaxC"][0])).to be_within(100).of(0)
|
19
|
-
expect(weather.data_forecast["weather"][0]["weatherDesc"][0]).to_not be_empty
|
20
|
-
expect(Integer(weather.data_forecast["weather"][0]["windspeedKmph"][0])).to be_within(100).of(100)
|
21
|
-
expect(weather.data_forecast["weather"][0]["winddir16Point"][0]).to_not be_empty
|
22
|
-
expect(Integer(weather.data_forecast["weather"][4]["tempMinC"][0])).to be_within(100).of(0)
|
23
|
-
expect(Integer(weather.data_forecast["weather"][4]["tempMaxC"][0])).to be_within(100).of(0)
|
24
|
-
expect(weather.data_forecast["weather"][4]["weatherDesc"][0]).to_not be_empty
|
25
|
-
expect(Integer(weather.data_forecast["weather"][4]["windspeedKmph"][0])).to be_within(100).of(100)
|
26
|
-
expect(weather.data_forecast["weather"][4]["winddir16Point"][0]).to_not be_empty
|
27
|
-
expect(weather.temperature).to be_within(100).of(0)
|
28
|
-
expect(weather.feels_like).to be_within(100).of(0)
|
29
|
-
expect(weather.observation_time.min).to be_within(30).of(30)
|
30
|
-
expect(weather.conditions).to_not be_empty
|
31
|
-
expect(weather.wind_speed).to_not be_empty
|
32
|
-
end
|
33
|
-
end
|