sunweather 0.2.0 → 0.3.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 +4 -4
- data/VERSION +1 -1
- data/lib/runner.rb +10 -4
- data/lib/sun.rb +4 -1
- data/lib/weather.rb +39 -0
- data/spec/sun_spec.rb +2 -1
- data/spec/weather_spec.rb +33 -0
- data/sunweather.gemspec +6 -3
- data/temp +4 -0
- metadata +5 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ccf57264d8f1a94497748defc696a25bab52ebbd
         | 
| 4 | 
            +
              data.tar.gz: 74a53502a0dbf686b88a66d22de0769eb5f4d4a6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c0cd89eac1a47f59ed9d30145e897a57a35a359f52620cfa574d8507b4d707bdfb4e0c5c17fda303d056aa300a2b5ec4bc91681fe5ebcb4b2b888e811e882d76
         | 
| 7 | 
            +
              data.tar.gz: ee6cdec86b8a18f75449d2949f8aabe9ff9e0022e3a732fea6e061ee532f8cd883f6918eb7c1b4d267ce1d3a24a40beb70bb684298316d353d51d242e9c2715a
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.3.0
         | 
    
        data/lib/runner.rb
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require_relative 'geo'
         | 
| 2 2 | 
             
            require_relative 'sun'
         | 
| 3 | 
            +
            require_relative 'weather'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Sunweather
         | 
| 5 6 | 
             
            	class Runner
         | 
| @@ -10,10 +11,15 @@ module Sunweather | |
| 10 11 | 
             
            		def run
         | 
| 11 12 | 
             
            			@geo = (ARGV[0] ? Geo.new(ARGV[0]) : Geo.new)
         | 
| 12 13 | 
             
            			@sun = Sun.new(@geo.lat, @geo.lng)
         | 
| 13 | 
            -
            			 | 
| 14 | 
            -
            			puts @sun.sunrise
         | 
| 15 | 
            -
            			puts @sun.sunset
         | 
| 16 | 
            -
            			puts @ | 
| 14 | 
            +
            			@weather = Weather.new(@geo.lat, @geo.lng)
         | 
| 15 | 
            +
            			puts "Dawn from #{hours_minutes(@sun.start_of_dawn)} to #{hours_minutes(@sun.sunrise)}"
         | 
| 16 | 
            +
            			puts "Dusk from #{hours_minutes(@sun.sunset)} to #{hours_minutes(@sun.end_of_dusk)}"
         | 
| 17 | 
            +
            			puts "Temperature: #{@weather.temperature}°C, feels like #{@weather.feels_like}°C"
         | 
| 18 | 
            +
            			puts "#{@weather.conditions} sky, #{@weather.wind_speed.downcase} wind from #{@weather.wind_direction}."
         | 
| 19 | 
            +
            		end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            		def hours_minutes time
         | 
| 22 | 
            +
            			"#{time.hour}:#{time.min+time.sec/30}"
         | 
| 17 23 | 
             
            		end
         | 
| 18 24 | 
             
            	end
         | 
| 19 25 | 
             
            end
         | 
    
        data/lib/sun.rb
    CHANGED
    
    | @@ -1,6 +1,5 @@ | |
| 1 1 | 
             
            require 'xmlsimple'
         | 
| 2 2 | 
             
            require 'open-uri'
         | 
| 3 | 
            -
            require 'awesome_print'
         | 
| 4 3 | 
             
            require 'date'
         | 
| 5 4 |  | 
| 6 5 | 
             
            module Sunweather
         | 
| @@ -53,5 +52,9 @@ module Sunweather | |
| 53 52 | 
             
            		def end_of_dusk
         | 
| 54 53 | 
             
            			Time.at(self.sunset.to_i + self.dawn_length.to_i)
         | 
| 55 54 | 
             
            		end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            		def hours_minutes time
         | 
| 57 | 
            +
            			"#{time.hour}:#{time.minute+time.second/30}"
         | 
| 58 | 
            +
            		end
         | 
| 56 59 | 
             
            	end
         | 
| 57 60 | 
             
            end
         | 
    
        data/lib/weather.rb
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 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
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 | 
            +
            require_relative "../lib/geo"
         | 
| 1 2 | 
             
            require_relative "../lib/sun"
         | 
| 2 3 |  | 
| 3 | 
            -
            describe Sunweather::Sun, "after initializing with  | 
| 4 | 
            +
            describe Sunweather::Sun, "after initializing with geocoordinates from default Geo object" do
         | 
| 4 5 | 
             
              let(:geo) { Sunweather::Geo.new }
         | 
| 5 6 | 
             
              let(:sun) { Sunweather::Sun.new(geo.lat, geo.lng) }
         | 
| 6 7 |  | 
| @@ -0,0 +1,33 @@ | |
| 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
         | 
    
        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. | 
| 8 | 
            +
              s.version = "0.3.0"
         | 
| 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-10- | 
| 12 | 
            +
              s.date = "2013-10-18"
         | 
| 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"]
         | 
| @@ -30,10 +30,13 @@ Gem::Specification.new do |s| | |
| 30 30 | 
             
                "lib/geo.rb",
         | 
| 31 31 | 
             
                "lib/runner.rb",
         | 
| 32 32 | 
             
                "lib/sun.rb",
         | 
| 33 | 
            +
                "lib/weather.rb",
         | 
| 33 34 | 
             
                "spec/geo_spec.rb",
         | 
| 34 35 | 
             
                "spec/spec_helper.rb",
         | 
| 35 36 | 
             
                "spec/sun_spec.rb",
         | 
| 36 | 
            -
                " | 
| 37 | 
            +
                "spec/weather_spec.rb",
         | 
| 38 | 
            +
                "sunweather.gemspec",
         | 
| 39 | 
            +
                "temp"
         | 
| 37 40 | 
             
              ]
         | 
| 38 41 | 
             
              s.homepage = "http://github.com/tobifrank/sunweather"
         | 
| 39 42 | 
             
              s.licenses = ["MIT"]
         | 
    
        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. | 
| 4 | 
            +
              version: 0.3.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- | 
| 11 | 
            +
            date: 2013-10-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| @@ -171,10 +171,13 @@ files: | |
| 171 171 | 
             
            - lib/geo.rb
         | 
| 172 172 | 
             
            - lib/runner.rb
         | 
| 173 173 | 
             
            - lib/sun.rb
         | 
| 174 | 
            +
            - lib/weather.rb
         | 
| 174 175 | 
             
            - spec/geo_spec.rb
         | 
| 175 176 | 
             
            - spec/spec_helper.rb
         | 
| 176 177 | 
             
            - spec/sun_spec.rb
         | 
| 178 | 
            +
            - spec/weather_spec.rb
         | 
| 177 179 | 
             
            - sunweather.gemspec
         | 
| 180 | 
            +
            - temp
         | 
| 178 181 | 
             
            homepage: http://github.com/tobifrank/sunweather
         | 
| 179 182 | 
             
            licenses:
         | 
| 180 183 | 
             
            - MIT
         |