sunweather 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7959e44051224f4ef0eaae0a721d5d617bf9e467
4
- data.tar.gz: 40c62de7d010e330c8b4a35965dc52686bfb0b5c
3
+ metadata.gz: 38c8f064c219168fc41eb8f91c750b9323602ee8
4
+ data.tar.gz: 1c6dae727724c6874a7903f0be62574fb280b945
5
5
  SHA512:
6
- metadata.gz: 30eada42b4b8584d8ecb0cce82b0ed2ebd002ff0a0632b3c68608bde28cf408c3f58ac5928413a0d235277f34a9304eaab56770d6e971734982c2873efd3e758
7
- data.tar.gz: bbf747fd11d6ca2da5b68353b918852744e8ed0fc3c2b546c56bb0d14a0f2db8f99dbd7f7c5d276cf81fe3143a2917d536dea4b34a02a5d39aecf8d34a8a8160
6
+ metadata.gz: 530e7eb65876a91c82d1345875794f16faa5c868fa456b09af247e98ca268ceb29005aad3426842e78e1af0a36176d88ed57331c585496be807264e5030d9eac
7
+ data.tar.gz: 97e2471d78cde0718fe8f948bad813b19dee29b45f94d7112e7c4b926af013f6be423a7e42e1702dcaac7bcf80a05d579d19b44d351cd078fa964b140b5c4aef
data/Gemfile CHANGED
@@ -14,4 +14,6 @@ group :development do
14
14
  gem "geocoder", "~> 1.1.8"
15
15
  gem "json", "~> 1.8.0"
16
16
  gem "capybara", "~> 2.1.0"
17
+ gem "xml-simple", "~> 1.1.2"
18
+ gem "awesome_print", "~> 1.1.0"
17
19
  end
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  addressable (2.3.5)
5
+ awesome_print (1.1.0)
5
6
  builder (3.2.2)
6
7
  capybara (2.1.0)
7
8
  mime-types (>= 1.16)
@@ -66,6 +67,7 @@ GEM
66
67
  multi_json (~> 1.0)
67
68
  simplecov-html (~> 0.7.1)
68
69
  simplecov-html (0.7.1)
70
+ xml-simple (1.1.2)
69
71
  xpath (2.0.0)
70
72
  nokogiri (~> 1.3)
71
73
 
@@ -73,6 +75,7 @@ PLATFORMS
73
75
  ruby
74
76
 
75
77
  DEPENDENCIES
78
+ awesome_print (~> 1.1.0)
76
79
  bundler (~> 1.0)
77
80
  capybara (~> 2.1.0)
78
81
  geocoder (~> 1.1.8)
@@ -81,3 +84,4 @@ DEPENDENCIES
81
84
  rdoc (~> 3.12)
82
85
  rspec (~> 2.8.0)
83
86
  simplecov
87
+ xml-simple (~> 1.1.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/geo.rb CHANGED
@@ -4,7 +4,7 @@ module Sunweather
4
4
  class Geo
5
5
  attr_reader :data
6
6
 
7
- def initialize (request = "Friedrich-von-Spee-Straße 10, Paderborn")
7
+ def initialize (request = ENV["FREEFORM_ADDRESS_QUERY"])
8
8
  @data = Geocoder.search(request)
9
9
  end
10
10
 
data/lib/runner.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'geo'
2
+ require_relative 'sun'
2
3
 
3
4
  module Sunweather
4
5
  class Runner
@@ -8,8 +9,11 @@ module Sunweather
8
9
 
9
10
  def run
10
11
  @geo = (ARGV[0] ? Geo.new(ARGV[0]) : Geo.new)
11
- puts @geo.lat
12
- puts @geo.lng
12
+ @sun = Sun.new(@geo.lat, @geo.lng)
13
+ puts @sun.start_of_dawn
14
+ puts @sun.sunrise
15
+ puts @sun.sunset
16
+ puts @sun.end_of_dusk
13
17
  end
14
18
  end
15
19
  end
data/lib/sun.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'xmlsimple'
2
+ require 'open-uri'
3
+ require 'awesome_print'
4
+ require 'date'
5
+
6
+ module Sunweather
7
+ class Sun
8
+ attr_reader :data_sunrise_sunset, :data_twilight
9
+
10
+ def initialize lat, lng
11
+ file = open("http://api.wunderground.com/api/#{ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]}/astronomy/q/#{lat},#{lng}.xml")
12
+ @data_sunrise_sunset = XmlSimple.xml_in(file)
13
+ file = open("http://www.earthtools.org/sun/#{lat}/#{lng}/#{Time.now.mday}/#{Time.now.mon}/99/0")
14
+ @data_twilight = XmlSimple.xml_in(file)
15
+ end
16
+
17
+ def sunrise
18
+ 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])
19
+ end
20
+
21
+ def sunset
22
+ 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])
23
+ end
24
+
25
+ def sunrise_earthtools
26
+ DateTime.parse(self.data_twilight["morning"][0]["sunrise"][0]).to_time
27
+ end
28
+
29
+ def sunset_earthtools
30
+ DateTime.parse(self.data_twilight["evening"][0]["sunset"][0]).to_time
31
+ end
32
+
33
+ def start_of_dawn_earthtools
34
+ DateTime.parse(self.data_twilight["morning"][0]["twilight"][0]["civil"][0]).to_time
35
+ end
36
+
37
+ def end_of_dusk_earthtools
38
+ DateTime.parse(self.data_twilight["evening"][0]["twilight"][0]["civil"][0]).to_time
39
+ end
40
+
41
+ def dawn_length
42
+ Time.at(self.sunrise_earthtools - self.start_of_dawn_earthtools)
43
+ end
44
+
45
+ def dusk_length
46
+ Time.at(self.end_of_dusk_earthtools - self.sunset_earthtools)
47
+ end
48
+
49
+ def start_of_dawn
50
+ Time.at(self.sunrise - self.dawn_length)
51
+ end
52
+
53
+ def end_of_dusk
54
+ Time.at(self.sunset.to_i + self.dawn_length.to_i)
55
+ end
56
+ end
57
+ end
data/spec/geo_spec.rb CHANGED
@@ -3,49 +3,23 @@ require_relative "../lib/geo"
3
3
  describe Sunweather::Geo, "after initializing with a string" do
4
4
  let (:geo) { Sunweather::Geo.new("test") }
5
5
 
6
- it "contains data" do
6
+ it "contains data which is useful" do
7
7
  expect(geo.data).not_to be_nil
8
+ expect(geo.data[0].data["geometry"]["location"]["lat"]).to be_within(90).of(0)
9
+ expect(geo.data[0].data["geometry"]["location"]["lng"]).to be_within(180).of(0)
10
+ expect(geo.lat).to be_within(90).of(0)
11
+ expect(geo.lng).to be_within(180).of(0)
8
12
  end
9
-
10
- it "contains a latitude value" do
11
- expect(geo.data[0].data["geometry"]["location"]["lat"]).to be_within(90).of(0)
12
- end
13
-
14
- it "contains a longitude value" do
15
- expect(geo.data[0].data["geometry"]["location"]["lng"]).to be_within(180).of(0)
16
- end
17
-
18
- it "returns a latitude value on lat" do
19
- expect(geo.lat).to be_within(90).of(0)
20
- end
21
-
22
- it "returns a longitude value on lng" do
23
- expect(geo.lng).to be_within(180).of(0)
24
- end
25
-
26
13
  end
27
14
 
28
15
  describe Sunweather::Geo, "after initializing without a string" do
29
16
  let (:geo) { Sunweather::Geo.new }
30
17
 
31
- it "contains data" do
18
+ it "contains data which is useful" do
32
19
  expect(geo.data).not_to be_nil
20
+ expect(geo.data[0].data["geometry"]["location"]["lat"]).to be_within(90).of(0)
21
+ expect(geo.data[0].data["geometry"]["location"]["lng"]).to be_within(180).of(0)
22
+ expect(geo.lat).to eq(51.713741)
23
+ expect(geo.lng).to eq(8.770812)
33
24
  end
34
-
35
- it "contains a latitude value" do
36
- expect(geo.data[0].data["geometry"]["location"]["lat"]).to be_within(90).of(0)
37
- end
38
-
39
- it "contains a longitude value" do
40
- expect(geo.data[0].data["geometry"]["location"]["lng"]).to be_within(180).of(0)
41
- end
42
-
43
- it "returns default latitude value on lat" do
44
- expect(geo.lat).to eq(51.713741)
45
- end
46
-
47
- it "returns default longitude value on lng" do
48
- expect(geo.lng).to eq(8.770812)
49
- end
50
-
51
25
  end
data/spec/sun_spec.rb ADDED
@@ -0,0 +1,49 @@
1
+ require_relative "../lib/sun"
2
+
3
+ describe Sunweather::Sun, "after initializing with a string" do
4
+ let(:geo) { Sunweather::Geo.new }
5
+ let(:sun) { Sunweather::Sun.new(geo.lat, geo.lng) }
6
+
7
+ it "contains the required data from Wunderground and Earthtools" do
8
+ expect(sun.data_sunrise_sunset).not_to be_nil
9
+ expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["hour"][0])).to be_within(12).of(12)
10
+ expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunrise"][0]["minute"][0])).to be_within(30).of(30)
11
+ expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["hour"][0])).to be_within(12).of(12)
12
+ expect(Integer(sun.data_sunrise_sunset["sun_phase"][0]["sunset"][0]["minute"][0])).to be_within(30).of(30)
13
+ expect(sun.sunrise.min).to be_within(30).of(30)
14
+ expect(sun.sunrise.hour).to be_within(12).of(12)
15
+ expect(sun.sunset.min).to be_within(30).of(30)
16
+ expect(sun.sunset.hour).to be_within(12).of(12)
17
+ expect(sun.data_twilight).not_to be_nil
18
+ expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).sec).to be_within(30).of(30)
19
+ expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).min).to be_within(30).of(30)
20
+ expect(DateTime.parse(sun.data_twilight["morning"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
21
+ expect(DateTime.parse(sun.data_twilight["evening"][0]["twilight"][0]["civil"][0]).hour).to be_within(30).of(30)
22
+ expect(DateTime.parse(sun.data_twilight["morning"][0]["sunrise"][0]).hour).to be_within(30).of(30)
23
+ expect(DateTime.parse(sun.data_twilight["evening"][0]["sunset"][0]).hour).to be_within(30).of(30)
24
+ expect(sun.sunrise_earthtools.sec).to be_within(30).of(30)
25
+ expect(sun.sunrise_earthtools.min).to be_within(30).of(30)
26
+ expect(sun.sunrise_earthtools.hour).to be_within(12).of(12)
27
+ expect(sun.sunset_earthtools.sec).to be_within(30).of(30)
28
+ expect(sun.sunset_earthtools.min).to be_within(30).of(30)
29
+ expect(sun.sunset_earthtools.hour).to be_within(12).of(12)
30
+ expect(sun.start_of_dawn_earthtools.sec).to be_within(30).of(30)
31
+ expect(sun.start_of_dawn_earthtools.min).to be_within(30).of(30)
32
+ expect(sun.start_of_dawn_earthtools.hour).to be_within(12).of(12)
33
+ expect(sun.end_of_dusk_earthtools.sec).to be_within(30).of(30)
34
+ expect(sun.end_of_dusk_earthtools.min).to be_within(30).of(30)
35
+ expect(sun.end_of_dusk_earthtools.hour).to be_within(12).of(12)
36
+ expect(sun.start_of_dawn.sec).to be_within(30).of(30)
37
+ expect(sun.start_of_dawn.min).to be_within(30).of(30)
38
+ expect(sun.start_of_dawn.hour).to be_within(12).of(12)
39
+ expect(sun.end_of_dusk.sec).to be_within(30).of(30)
40
+ expect(sun.end_of_dusk.min).to be_within(30).of(30)
41
+ expect(sun.end_of_dusk.hour).to be_within(12).of(12)
42
+ expect(sun.dawn_length.sec).to be_within(30).of(30)
43
+ expect(sun.dawn_length.min).to be_within(30).of(30)
44
+ expect(sun.dawn_length.hour).to be_within(12).of(12)
45
+ expect(sun.dusk_length.sec).to be_within(30).of(30)
46
+ expect(sun.dusk_length.min).to be_within(30).of(30)
47
+ expect(sun.dusk_length.hour).to be_within(12).of(12)
48
+ end
49
+ end
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sunweather"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tobi Frank"]
12
+ s.date = "2013-10-17"
13
+ s.description = "Provides sunrise/sunset and weather info for given address."
14
+ s.email = "tobifrank38@gmail.com"
15
+ s.executables = ["sunweather"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/sunweather",
30
+ "lib/geo.rb",
31
+ "lib/runner.rb",
32
+ "lib/sun.rb",
33
+ "spec/geo_spec.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/sun_spec.rb",
36
+ "sunweather.gemspec"
37
+ ]
38
+ s.homepage = "http://github.com/tobifrank/sunweather"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "2.0.3"
42
+ s.summary = "Provides sunrise/sunset and weather info for given address."
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 4
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
49
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
52
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
53
+ s.add_development_dependency(%q<geocoder>, ["~> 1.1.8"])
54
+ s.add_development_dependency(%q<json>, ["~> 1.8.0"])
55
+ s.add_development_dependency(%q<capybara>, ["~> 2.1.0"])
56
+ s.add_development_dependency(%q<xml-simple>, ["~> 1.1.2"])
57
+ s.add_development_dependency(%q<awesome_print>, ["~> 1.1.0"])
58
+ else
59
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
63
+ s.add_dependency(%q<simplecov>, [">= 0"])
64
+ s.add_dependency(%q<geocoder>, ["~> 1.1.8"])
65
+ s.add_dependency(%q<json>, ["~> 1.8.0"])
66
+ s.add_dependency(%q<capybara>, ["~> 2.1.0"])
67
+ s.add_dependency(%q<xml-simple>, ["~> 1.1.2"])
68
+ s.add_dependency(%q<awesome_print>, ["~> 1.1.0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
72
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
73
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
74
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
75
+ s.add_dependency(%q<simplecov>, [">= 0"])
76
+ s.add_dependency(%q<geocoder>, ["~> 1.1.8"])
77
+ s.add_dependency(%q<json>, ["~> 1.8.0"])
78
+ s.add_dependency(%q<capybara>, ["~> 2.1.0"])
79
+ s.add_dependency(%q<xml-simple>, ["~> 1.1.2"])
80
+ s.add_dependency(%q<awesome_print>, ["~> 1.1.0"])
81
+ end
82
+ end
83
+
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.1.0
4
+ version: 0.2.0
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-10-14 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: 2.1.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: xml-simple
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 1.1.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 1.1.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.1.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.1.0
125
153
  description: Provides sunrise/sunset and weather info for given address.
126
154
  email: tobifrank38@gmail.com
127
155
  executables:
@@ -142,8 +170,11 @@ files:
142
170
  - bin/sunweather
143
171
  - lib/geo.rb
144
172
  - lib/runner.rb
173
+ - lib/sun.rb
145
174
  - spec/geo_spec.rb
146
175
  - spec/spec_helper.rb
176
+ - spec/sun_spec.rb
177
+ - sunweather.gemspec
147
178
  homepage: http://github.com/tobifrank/sunweather
148
179
  licenses:
149
180
  - MIT