forecastr 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9575109a60c5803a952035bf13e04107dd25f17a
4
- data.tar.gz: fec0d1971cfbd5755ed2476f6720503cac9a021c
3
+ metadata.gz: 5cffd26866155781856d6e6502d6d1c11ca6db40
4
+ data.tar.gz: 89de042eefbdfb4e49b584203e5ba12346c2d5a3
5
5
  SHA512:
6
- metadata.gz: aaf155808d600eb46cdae85b1f36607f7e5295176d9e11d1cf897898bfd2540c889c8b4e5042ed9216c18331a52aa1abf6f4a12777be95de39296830467c8f90
7
- data.tar.gz: 1f1af391d6dc84c8662eae0c0f89bc1d05220c63f8079d00e007bd37dc4ebbc341556b7c919dc885f8f7697fa3aaa59013e98e2063435c3c85d947099adeeb35
6
+ metadata.gz: 893ce64e40851ab239770e65c5a023999f7b188e5d7f2330e4ed79dd4edd03fa71f3132cff0eefe71aed6ae4679a0f897c7a9595428925bedd1dc49d66bf8c0b
7
+ data.tar.gz: 29071cd3a3cf4a8e3498fd34df79859d769887282e22ec99f2036e5a136c0ad1eb819dfe66d0f0f1ce5acc11be8ff56a9df0319094d9baad5113ff6d9fc42fdd
@@ -2,7 +2,7 @@ module Forecastr
2
2
  class DataContainer
3
3
 
4
4
  attr_reader :city, :longitude, :latitude, :pressure, :humidity, :clouds,
5
- :temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle
5
+ :temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle, :sunrise, :sunset
6
6
 
7
7
  def initialize(json)
8
8
  @city = json['name']
@@ -16,6 +16,8 @@ module Forecastr
16
16
  @clouds = json['clouds']['all']
17
17
  @wind_speed = json['wind']['speed']
18
18
  @wind_angle = json['wind']['deg']
19
+ @sunrise = json['sys']['sunrise'].to_s
20
+ @sunset = json['sys']['sunset'].to_s
19
21
  end
20
22
  end
21
23
  end
@@ -1,9 +1,11 @@
1
+ require 'date'
2
+
1
3
  module Forecastr
2
4
  class Forecast
3
5
 
4
6
  attr_reader :city, :longitude, :latitude, :temperature,
5
7
  :pressure, :humidity, :min_temperature,
6
- :max_temperature, :clouds, :wind
8
+ :max_temperature, :clouds, :wind, :sunrise, :sunset
7
9
 
8
10
  def initialize(data)
9
11
  @city = data.city
@@ -16,6 +18,8 @@ module Forecastr
16
18
  @max_temperature = Forecastr::Temperature.new(data.max_temperature)
17
19
  @clouds = data.clouds
18
20
  @wind = Forecastr::Wind.new(data.wind_speed, data.wind_angle)
21
+ @sunset = DateTime.strptime(data.sunset, '%s')
22
+ @sunrise = DateTime.strptime(data.sunrise, '%s')
19
23
  end
20
24
 
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module Forecastr
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,12 +1 @@
1
- {"id":88319,"dt":1345284000,"name":"Benghazi",
2
- "coord":{"lat":32.12,"lon":20.07},
3
- "main":{"temp":306.15,"pressure":1013,"humidity":44,"temp_min":306,"temp_max":306},
4
- "wind":{"speed":1,"deg":-7},
5
- "weather":[
6
- {"id":520,"main":"Rain","description":"light intensity shower rain","icon":"09d"},
7
- {"id":500,"main":"Rain","description":"light rain","icon":"10d"},
8
- {"id":701,"main":"Mist","description":"mist","icon":"50d"}
9
- ],
10
- "clouds":{"all":90},
11
- "rain":{"3h":3}
12
- }
1
+ {"coord":{"lon":-0.13,"lat":51.51},"sys":{"message":0.0846,"country":"GB","sunrise":1395640357,"sunset":1395685239},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"cmc stations","main":{"temp":279.64,"humidity":55,"pressure":1003,"temp_min":278.71,"temp_max":280.37},"wind":{"speed":2.06,"gust":3.6,"deg":350},"clouds":{"all":92},"dt":1395699452,"id":2643743,"name":"London","cod":200}
@@ -16,5 +16,7 @@ describe Forecastr::DataContainer do
16
16
  expect(container.clouds).to eq 0
17
17
  expect(container.wind_speed).to eq 1.16
18
18
  expect(container.wind_angle).to eq 128.501
19
+ expect(container.sunrise).to eq '1395376499'
20
+ expect(container.sunset).to eq '1395420461'
19
21
  end
20
22
  end
@@ -1,21 +1,29 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe Forecastr::Forecast do
4
- let(:json) { JSON.parse(fixture('data.json').read) }
4
+ let(:json) { JSON.parse(fixture('london.json').read) }
5
5
  let(:data) { Forecastr::DataContainer.new(json) }
6
6
  let(:forecast) { Forecastr::Forecast.new(data) }
7
7
 
8
8
  it 'has a city' do
9
- expect(forecast.city).to eq "Benghazi"
9
+ expect(forecast.city).to eq "London"
10
+ end
11
+
12
+ it 'has time of sunrise' do
13
+ expect(forecast.sunrise).to eq DateTime.parse("2014-03-21T05:59:29+00:00")
14
+ end
15
+
16
+ it 'has time of sunset' do
17
+ expect(forecast.sunset).to eq DateTime.parse("2014-03-21 19:15:36 +0100")
10
18
  end
11
19
 
12
20
  describe 'coordinates' do
13
21
  it 'has longitude' do
14
- expect(forecast.longitude).to eq 20.07
22
+ expect(forecast.longitude).to eq -0.13
15
23
  end
16
24
 
17
25
  it 'has latitude' do
18
- expect(forecast.latitude).to eq 32.12
26
+ expect(forecast.latitude).to eq 51.51
19
27
  end
20
28
  end
21
29
 
@@ -23,42 +31,42 @@ describe Forecastr::Forecast do
23
31
  describe 'temperatures' do
24
32
  context 'celsius' do
25
33
  it 'has current temperature' do
26
- expect(forecast.temperature.to_celsius).to eq 33.0
34
+ expect(forecast.temperature.to_celsius).to eq 7.64
27
35
  end
28
36
 
29
37
  it 'has minimal temperature' do
30
- expect(forecast.min_temperature.to_celsius).to eq 32.85
38
+ expect(forecast.min_temperature.to_celsius).to eq 6.11
31
39
  end
32
40
 
33
41
  it 'has maximal temperature' do
34
- expect(forecast.max_temperature.to_celsius).to eq 32.85
42
+ expect(forecast.max_temperature.to_celsius).to eq 9.0
35
43
  end
36
44
  end
37
45
  end
38
46
 
39
47
  it 'has pressure' do
40
- expect(forecast.pressure).to eq 1013
48
+ expect(forecast.pressure).to eq 1001
41
49
  end
42
50
 
43
51
  it 'has humidity' do
44
- expect(forecast.humidity).to eq 44
52
+ expect(forecast.humidity).to eq 70
45
53
  end
46
54
 
47
55
  end
48
56
 
49
57
  describe 'clouds' do
50
58
  it 'has cloud coverage in %' do
51
- expect(forecast.clouds).to eq 90
59
+ expect(forecast.clouds).to eq 92
52
60
  end
53
61
  end
54
62
 
55
63
  describe 'wind' do
56
64
  it 'has speed in m/s' do
57
- expect(forecast.wind.speed).to eq "1 m/s"
65
+ expect(forecast.wind.speed).to eq "5.1 m/s"
58
66
  end
59
67
 
60
68
  it 'has direction' do
61
- expect(forecast.wind.direction).to eq "N"
69
+ expect(forecast.wind.direction).to eq "S"
62
70
  end
63
71
  end
64
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forecastr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ile Eftimov