knmi 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,180 @@
1
+ require 'helper'
2
+
3
+ class TestParameters < KNMI::TestCase
4
+ context "find all daily" do
5
+ setup do
6
+ @params = KNMI::Parameters.all("daily")
7
+ end
8
+
9
+ should "by an array" do
10
+ assert_equal @params.class, Array
11
+ end
12
+
13
+ should "contain KNMI::Parameters object" do
14
+ assert_equal @params[0].class, KNMI::Parameters
15
+ end
16
+
17
+ should "be length 40" do
18
+ assert_equal @params.length, 40
19
+ end
20
+ end
21
+
22
+ context "find all hourly" do
23
+ setup do
24
+ @params = KNMI::Parameters.all("hourly")
25
+ end
26
+
27
+ should "be an array" do
28
+ assert_equal @params.class, Array
29
+ end
30
+
31
+ should "contain KNMI::Parameters object" do
32
+ assert_equal @params[0].class, KNMI::Parameters
33
+ end
34
+
35
+ should "be length 23" do
36
+ assert_equal @params.length, 23
37
+ end
38
+ end
39
+
40
+ context "find a single daily parameter" do
41
+ setup do
42
+ @params = KNMI::Parameters.find(period = "daily", "TX")
43
+ end
44
+
45
+ should "be an array" do
46
+ assert_equal @params.class, Array
47
+ end
48
+
49
+ should "contain KNMI::Parameters object" do
50
+ assert_equal @params[0].class, KNMI::Parameters
51
+ end
52
+
53
+ should "access parameter id" do
54
+ assert_equal @params[0].parameter, "TX"
55
+ end
56
+
57
+ should "access category id" do
58
+ assert_equal @params[0].category, "TEMP"
59
+ end
60
+
61
+ should "access description id" do
62
+ assert_contains @params[0].description, "Maximum Temperature"
63
+ end
64
+
65
+ should "access validation equation" do
66
+ assert_equal @params[0].validate, "n.integer?"
67
+ end
68
+
69
+ should "access conversion equation" do
70
+ assert_equal @params[0].conversion, "n / 10"
71
+ end
72
+
73
+ should "access units" do
74
+ assert_equal @params[0].units, "C"
75
+ end
76
+ end
77
+
78
+ context "find a mutliple daily parameter" do
79
+ setup do
80
+ @params = KNMI::Parameters.find(period = "daily", ["TX", "SP"])
81
+ end
82
+
83
+ should "by an array" do
84
+ assert_equal @params.class, Array
85
+ end
86
+
87
+ should "be length 2" do
88
+ assert_equal @params.length, 2
89
+ end
90
+
91
+ should "contain KNMI::Parameters object" do
92
+ assert_equal @params[0].class, KNMI::Parameters
93
+ end
94
+
95
+ should "contain KNMI::Parameters object with parameter TX" do
96
+ assert_equal @params[0].parameter, "TX"
97
+ end
98
+
99
+ should "contain KNMI::Parameters object with parameter SP" do
100
+ assert_equal @params[1].parameter, "SP"
101
+ end
102
+ end
103
+
104
+ context "find a single hourly parameter" do
105
+ setup do
106
+ @params = KNMI::Parameters.find(period = "hourly", "T")
107
+ end
108
+
109
+ should "contain KNMI::Parameters object" do
110
+ assert_equal @params[0].class, KNMI::Parameters
111
+ end
112
+
113
+ should "access parameter id" do
114
+ assert_equal @params[0].parameter, "T"
115
+ end
116
+
117
+ should "access category id" do
118
+ assert_equal @params[0].category, "TEMP"
119
+ end
120
+
121
+ should "access description id" do
122
+ assert_equal @params[0].description, "Air Temperature at 1.5 m"
123
+ end
124
+
125
+ should "access validation equation" do
126
+ assert_equal @params[0].validate, "n.integer?"
127
+ end
128
+
129
+ should "access conversion equation" do
130
+ assert_equal @params[0].conversion, "n / 10"
131
+ end
132
+
133
+ should "access units" do
134
+ assert_equal @params[0].units, "C"
135
+ end
136
+ end
137
+
138
+ context "find a mutliple hourly parameter" do
139
+ setup do
140
+ @params = KNMI::Parameters.find(period = "hourly", category = ["T", "T10N"])
141
+ end
142
+
143
+ should "by an array" do
144
+ assert_equal @params.class, Array
145
+ end
146
+
147
+ should "contain KNMI::Parameters object" do
148
+ assert_equal @params[0].class, KNMI::Parameters
149
+ end
150
+ end
151
+
152
+ context "find parameters from category" do
153
+ setup do
154
+ @params = KNMI::Parameters.category(period = "hourly", "TEMP")
155
+ end
156
+
157
+ should "contain KNMI::Parameters object" do
158
+ assert_equal @params.class, Array
159
+ end
160
+
161
+ should "be length 3" do
162
+ assert_equal @params.length, 3
163
+ end
164
+ end
165
+
166
+ context "find parameters from two categories" do
167
+ setup do
168
+ @params = KNMI::Parameters.category(period = "hourly", ["TEMP", "WIND"])
169
+ end
170
+
171
+ should "contain KNMI::Parameters object" do
172
+ assert_equal @params.class, Array
173
+ end
174
+
175
+ should "be length 7" do
176
+ assert_equal @params.length, 7
177
+ end
178
+ end
179
+
180
+ end
@@ -0,0 +1,102 @@
1
+ require 'helper'
2
+
3
+ class TestKNMI < KNMI::TestCase
4
+ context "find a station by id" do
5
+ setup do
6
+ @station = KNMI::Station.find(210)
7
+ end
8
+
9
+ should "be a KNMI::Station class" do
10
+ assert_equal @station.class, KNMI::Station
11
+ end
12
+
13
+ should 'find id 210' do
14
+ assert_equal @station.id, 210
15
+ end
16
+
17
+ should "should return coordinates" do
18
+ assert_equal @station.coordinates, GeoKit::LatLng.new(52.165, 4.419)
19
+ end
20
+
21
+ should "return station city name" do
22
+ assert_equal @station.name, "Valkenburg"
23
+ end
24
+
25
+ should "return elevation" do
26
+ assert_equal @station.elevation, -0.20
27
+ end
28
+
29
+ should "return station photo url" do
30
+ assert_equal @station.photo, "http://www.knmi.nl/klimatologie/metadata/210_valkenburg_big.jpg"
31
+ end
32
+
33
+ should "return station map url" do
34
+ assert_equal @station.map, "http://www.knmi.nl/klimatologie/metadata/stn_210.gif"
35
+ end
36
+
37
+ should "return station web url" do
38
+ assert_equal @station.web, "http://www.knmi.nl/klimatologie/metadata/valkenburg.html"
39
+ end
40
+
41
+ should "contain hash with list and dates of instrumentation" do
42
+ assert_equal @station.instrumentation.class, Hash
43
+ end
44
+
45
+ end
46
+
47
+
48
+ context "find closest to coordinates" do
49
+ setup do
50
+ @station = KNMI::Station.closest_to(GeoKit::LatLng.new(52.165, 4.419))
51
+ end
52
+
53
+ should "be a KNMI::Station class" do
54
+ assert_equal @station.class, KNMI::Station
55
+ end
56
+
57
+ should 'find id 210' do
58
+ assert_equal @station.id, 210
59
+ end
60
+ end
61
+
62
+ context "find closest to lat/lng" do
63
+ setup do
64
+ @station = KNMI::Station.closest_to(52.165, 4.419)
65
+ end
66
+
67
+ should "be a KNMI::Station class" do
68
+ assert_equal @station.class, KNMI::Station
69
+ end
70
+
71
+
72
+ should 'find id 210' do
73
+ assert_equal @station.id, 210
74
+ end
75
+ end
76
+
77
+ context "find closest to lat/lng passed as an array" do
78
+ setup do
79
+ @station = KNMI::Station.closest_to([52.165, 4.419])
80
+ end
81
+
82
+ should "be a KNMI::Station class" do
83
+ assert_equal @station.class, KNMI::Station
84
+ end
85
+
86
+ should 'find id 210' do
87
+ assert_equal @station.id, 210
88
+ end
89
+ end
90
+
91
+ # TODO
92
+ # test 'should throw ArgumentError if bad argument passed into #closest_to()' do
93
+ # lambda { KNMI::Station.closest_to('hey') }.should raise_error(ArgumentError)
94
+ # end
95
+ #
96
+ # test 'should throw ArgumentError if more than two arguments passed into #closest_to()' do
97
+ # lambda { KNMI::Station.closest_to(1, 2, 3) }.should raise_error(ArgumentError)
98
+ # end
99
+ #
100
+
101
+
102
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knmi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - bullfight
@@ -10,22 +10,55 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-02 00:00:00 Z
13
+ date: 2011-05-17 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: shoulda
16
+ name: httparty
17
17
  requirement: &id001 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ">="
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: "0"
23
- type: :development
22
+ version: 0.7.7
23
+ type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: bundler
27
+ name: geokit
28
28
  requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.11.3
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda-context
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0.beta1
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: bundler
61
+ requirement: &id005 !ruby/object:Gem::Requirement
29
62
  none: false
30
63
  requirements:
31
64
  - - ~>
@@ -33,10 +66,10 @@ dependencies:
33
66
  version: 1.0.0
34
67
  type: :development
35
68
  prerelease: false
36
- version_requirements: *id002
69
+ version_requirements: *id005
37
70
  - !ruby/object:Gem::Dependency
38
71
  name: jeweler
39
- requirement: &id003 !ruby/object:Gem::Requirement
72
+ requirement: &id006 !ruby/object:Gem::Requirement
40
73
  none: false
41
74
  requirements:
42
75
  - - ~>
@@ -44,10 +77,10 @@ dependencies:
44
77
  version: 1.5.2
45
78
  type: :development
46
79
  prerelease: false
47
- version_requirements: *id003
80
+ version_requirements: *id006
48
81
  - !ruby/object:Gem::Dependency
49
82
  name: rcov
50
- requirement: &id004 !ruby/object:Gem::Requirement
83
+ requirement: &id007 !ruby/object:Gem::Requirement
51
84
  none: false
52
85
  requirements:
53
86
  - - ">="
@@ -55,10 +88,21 @@ dependencies:
55
88
  version: "0"
56
89
  type: :development
57
90
  prerelease: false
58
- version_requirements: *id004
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: pry
94
+ requirement: &id008 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: 0.8.3
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *id008
59
103
  - !ruby/object:Gem::Dependency
60
104
  name: httparty
61
- requirement: &id005 !ruby/object:Gem::Requirement
105
+ requirement: &id009 !ruby/object:Gem::Requirement
62
106
  none: false
63
107
  requirements:
64
108
  - - ">="
@@ -66,7 +110,7 @@ dependencies:
66
110
  version: 0.7.4
67
111
  type: :runtime
68
112
  prerelease: false
69
- version_requirements: *id005
113
+ version_requirements: *id009
70
114
  description: A set of methods to query the KNMI HTTP get form for daily climate data and select a variety of measured parameters, from available stations, in a json style array of hashes, and if necessary convert to csv.
71
115
  email: p.schmitz@gmail.com
72
116
  executables: []
@@ -77,6 +121,7 @@ extra_rdoc_files:
77
121
  - LICENSE.txt
78
122
  - README.rdoc
79
123
  files:
124
+ - .DS_Store
80
125
  - .document
81
126
  - Gemfile
82
127
  - Gemfile.lock
@@ -84,10 +129,21 @@ files:
84
129
  - README.rdoc
85
130
  - Rakefile
86
131
  - VERSION
132
+ - data/current_stations.yml
133
+ - data/daily_data_key.yml
134
+ - data/data_key.yml
135
+ - data/hourly_data_key.yml
87
136
  - knmi.gemspec
137
+ - lib/.DS_Store
88
138
  - lib/knmi.rb
139
+ - lib/knmi/httpservice.rb
140
+ - lib/knmi/parameters.rb
141
+ - lib/knmi/station.rb
89
142
  - test/helper.rb
143
+ - test/test_httpservice.rb
90
144
  - test/test_knmi.rb
145
+ - test/test_parameters.rb
146
+ - test/test_station.rb
91
147
  homepage: http://github.com/bullfight/knmi
92
148
  licenses:
93
149
  - MIT
@@ -101,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
157
  requirements:
102
158
  - - ">="
103
159
  - !ruby/object:Gem::Version
104
- hash: -3374246845192166730
160
+ hash: 1440179461476455421
105
161
  segments:
106
162
  - 0
107
163
  version: "0"
@@ -120,4 +176,7 @@ specification_version: 3
120
176
  summary: Ruby API to access daily climate data from the Royal Netherlands Meteorological Institute
121
177
  test_files:
122
178
  - test/helper.rb
179
+ - test/test_httpservice.rb
123
180
  - test/test_knmi.rb
181
+ - test/test_parameters.rb
182
+ - test/test_station.rb