weather_in_poland 0.0.4 → 0.0.5
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/README.textile +44 -0
- data/lib/weather_in_poland/version.rb +1 -1
- data/lib/weather_in_poland.rb +29 -0
- data/test/test.rb +20 -7
- metadata +4 -4
- data/test/.test.rb.swp +0 -0
data/README.textile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Weather in Poland is a simple extension for yahoo-weather gem.
|
2
|
+
|
3
|
+
h1. Dependencies:
|
4
|
+
|
5
|
+
* yahoo-weather
|
6
|
+
* mechanize
|
7
|
+
|
8
|
+
h1. Instalation:
|
9
|
+
|
10
|
+
gem install weather-in-poland
|
11
|
+
|
12
|
+
h1. Usage:
|
13
|
+
|
14
|
+
#initialize
|
15
|
+
|
16
|
+
w = WeatherInPoland.new
|
17
|
+
|
18
|
+
#this method return two things:
|
19
|
+
|
20
|
+
w.find_city('Pomorskie, Gdynia')
|
21
|
+
|
22
|
+
#name of city
|
23
|
+
|
24
|
+
w.city #in ex. Gdynia
|
25
|
+
|
26
|
+
#code for this city
|
27
|
+
|
28
|
+
w.code #in ex. 493421
|
29
|
+
|
30
|
+
#now we can use that code to get weather information
|
31
|
+
|
32
|
+
weather = w.get_weather(w.code)
|
33
|
+
|
34
|
+
#and images
|
35
|
+
|
36
|
+
w.get_image(weather)
|
37
|
+
|
38
|
+
#No we have access to 2 images:
|
39
|
+
* normal w.image
|
40
|
+
* thumb w.thumb
|
41
|
+
|
42
|
+
#Other weather info that same as in yahoo-weather:
|
43
|
+
|
44
|
+
pp weather #to see all
|
data/lib/weather_in_poland.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
require "yahoo-weather"
|
2
|
+
require "mechanize"
|
3
|
+
|
1
4
|
class WeatherInPoland
|
2
5
|
attr_reader :city
|
3
6
|
attr_reader :code
|
4
7
|
attr_reader :image
|
5
8
|
attr_reader :thumb
|
9
|
+
attr_reader :wind_direction
|
6
10
|
|
7
11
|
def find_city(name='Gdynia')
|
8
12
|
agent = Mechanize.new
|
@@ -28,6 +32,31 @@ class WeatherInPoland
|
|
28
32
|
return response
|
29
33
|
end
|
30
34
|
|
35
|
+
def get_wind_direction(data)
|
36
|
+
wind = data.wind.direction
|
37
|
+
if (wind>338)
|
38
|
+
@wind_direction = "N"
|
39
|
+
elsif (wind==0 && wind<24)
|
40
|
+
@wind_direction = "N"
|
41
|
+
elsif (wind>=24 && wind<69)
|
42
|
+
@wind_direction = "NE"
|
43
|
+
elsif (wind>=69 && wind<114)
|
44
|
+
@wind_direction = "E"
|
45
|
+
elsif (wind>=114 && wind<186)
|
46
|
+
@wind_direction = "SE"
|
47
|
+
elsif (wind>=186 && wind<204)
|
48
|
+
@wind_direction = "S"
|
49
|
+
elsif (wind>=204 && wind<249)
|
50
|
+
@wind_direction = "SW"
|
51
|
+
elsif (wind>=249 && wind<294)
|
52
|
+
@wind_direction = "W"
|
53
|
+
elsif (wind>=294 && wind<338)
|
54
|
+
@wind_direction = "NW"
|
55
|
+
else
|
56
|
+
@wind_direction = ""
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
31
60
|
def get_image(dane)
|
32
61
|
sun_rise = dane.astronomy.sunrise
|
33
62
|
sun_set = dane.astronomy.sunset
|
data/test/test.rb
CHANGED
@@ -8,23 +8,36 @@ class TestAPI < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
def setup
|
10
10
|
@weather = WeatherInPoland.new
|
11
|
+
@response = @weather.find_city
|
11
12
|
end
|
12
|
-
|
13
|
-
|
14
|
-
def test_all
|
13
|
+
|
14
|
+
def test_find_city
|
15
15
|
location = 'Pomorskie, Gdynia'
|
16
16
|
correct_city = 'Gdynia'
|
17
17
|
correct_code = 493421
|
18
|
+
|
19
|
+
assert @response
|
18
20
|
|
19
|
-
response = @weather.find_city(location)
|
20
|
-
assert(response)
|
21
21
|
assert_equal(correct_city, @weather.city)
|
22
22
|
assert_equal(correct_code, @weather.code)
|
23
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_weather
|
24
26
|
@data = @weather.get_weather(@weather.code)
|
25
27
|
assert_not_nil(@data)
|
26
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_wind_direction
|
31
|
+
@data = @weather.get_weather(@weather.code)
|
32
|
+
direction = get_wind_direction(@data)
|
33
|
+
assert_not_nil direction
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_image
|
37
|
+
@data = @weather.get_weather(@weather.code)
|
27
38
|
assert_not_nil(@data.condition.code)
|
39
|
+
assert_not_nil(@data.astronomy.sunrise)
|
40
|
+
assert_not_nil(@data.astronomy.sunset)
|
28
41
|
end
|
29
42
|
|
30
43
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_in_poland
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Oskar Szrajer
|
@@ -58,10 +58,10 @@ extra_rdoc_files: []
|
|
58
58
|
files:
|
59
59
|
- .gitignore
|
60
60
|
- Gemfile
|
61
|
+
- README.textile
|
61
62
|
- Rakefile
|
62
63
|
- lib/weather_in_poland.rb
|
63
64
|
- lib/weather_in_poland/version.rb
|
64
|
-
- test/.test.rb.swp
|
65
65
|
- test/test.rb
|
66
66
|
- weather_in_poland.gemspec
|
67
67
|
has_rdoc: true
|
data/test/.test.rb.swp
DELETED
Binary file
|