weatherzone 0.5.8

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.
Files changed (79) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +51 -0
  3. data/README.txt +30 -0
  4. data/Rakefile +7 -0
  5. data/bin/weatherzone +0 -0
  6. data/lib/ext/class.rb +175 -0
  7. data/lib/ext/object.rb +74 -0
  8. data/lib/tzinfo/definitions/Australia/CDT.rb +13 -0
  9. data/lib/tzinfo/definitions/Australia/CST.rb +13 -0
  10. data/lib/tzinfo/definitions/Australia/EDT.rb +13 -0
  11. data/lib/tzinfo/definitions/Australia/EST.rb +13 -0
  12. data/lib/tzinfo/definitions/Australia/WDT.rb +13 -0
  13. data/lib/tzinfo/definitions/Australia/WST.rb +13 -0
  14. data/lib/vendor/openuri_memcached/History.txt +18 -0
  15. data/lib/vendor/openuri_memcached/License.txt +20 -0
  16. data/lib/vendor/openuri_memcached/README.markdown +48 -0
  17. data/lib/vendor/openuri_memcached/lib/openuri/common.rb +117 -0
  18. data/lib/vendor/openuri_memcached/lib/openuri/memcached.rb +36 -0
  19. data/lib/vendor/openuri_memcached/lib/openuri/rails-cache.rb +21 -0
  20. data/lib/vendor/openuri_memcached/lib/openuri_memcached.rb +1 -0
  21. data/lib/weatherzone.rb +39 -0
  22. data/lib/weatherzone/connection.rb +85 -0
  23. data/lib/weatherzone/finder.rb +129 -0
  24. data/lib/weatherzone/helpers/almanac_element.rb +28 -0
  25. data/lib/weatherzone/helpers/date_parser.rb +33 -0
  26. data/lib/weatherzone/helpers/units.rb +76 -0
  27. data/lib/weatherzone/resource.rb +46 -0
  28. data/lib/weatherzone/resources/almanac.rb +18 -0
  29. data/lib/weatherzone/resources/almanac_period.rb +51 -0
  30. data/lib/weatherzone/resources/climate_period.rb +8 -0
  31. data/lib/weatherzone/resources/conditions.rb +19 -0
  32. data/lib/weatherzone/resources/country.rb +4 -0
  33. data/lib/weatherzone/resources/daily_observation.rb +10 -0
  34. data/lib/weatherzone/resources/district_forecast.rb +5 -0
  35. data/lib/weatherzone/resources/forecast.rb +47 -0
  36. data/lib/weatherzone/resources/historical_observation.rb +57 -0
  37. data/lib/weatherzone/resources/image.rb +9 -0
  38. data/lib/weatherzone/resources/lift.rb +3 -0
  39. data/lib/weatherzone/resources/location.rb +100 -0
  40. data/lib/weatherzone/resources/marine_forecast.rb +9 -0
  41. data/lib/weatherzone/resources/marine_summary.rb +8 -0
  42. data/lib/weatherzone/resources/moon_phase.rb +23 -0
  43. data/lib/weatherzone/resources/news_item.rb +18 -0
  44. data/lib/weatherzone/resources/point_forecast.rb +40 -0
  45. data/lib/weatherzone/resources/snow_report.rb +5 -0
  46. data/lib/weatherzone/resources/state_forecast.rb +4 -0
  47. data/lib/weatherzone/resources/surf_report.rb +5 -0
  48. data/lib/weatherzone/resources/tide.rb +9 -0
  49. data/lib/weatherzone/resources/warning.rb +21 -0
  50. data/lib/weatherzone/resources/weather.rb +14 -0
  51. data/test/test_almanac.rb +25 -0
  52. data/test/test_almanac_period.rb +33 -0
  53. data/test/test_buoy_observation.rb +24 -0
  54. data/test/test_climate_period.rb +29 -0
  55. data/test/test_conditions.rb +32 -0
  56. data/test/test_connection.rb +28 -0
  57. data/test/test_country.rb +29 -0
  58. data/test/test_daily_observation.rb +29 -0
  59. data/test/test_district_forecast.rb +23 -0
  60. data/test/test_farenheit_conversion_factor.rb +48 -0
  61. data/test/test_finder.rb +148 -0
  62. data/test/test_forecast.rb +30 -0
  63. data/test/test_helper.rb +38 -0
  64. data/test/test_historical_observation.rb +32 -0
  65. data/test/test_image.rb +23 -0
  66. data/test/test_location.rb +70 -0
  67. data/test/test_marine_forecast.rb +27 -0
  68. data/test/test_marine_summary.rb +24 -0
  69. data/test/test_moon_phase.rb +33 -0
  70. data/test/test_news_item.rb +22 -0
  71. data/test/test_point_forecast.rb +24 -0
  72. data/test/test_snow_report.rb +27 -0
  73. data/test/test_state_forecast.rb +23 -0
  74. data/test/test_surf_report.rb +22 -0
  75. data/test/test_tide.rb +23 -0
  76. data/test/test_value_and_unit_helpers.rb +45 -0
  77. data/test/test_warning.rb +23 -0
  78. data/test/test_weather.rb +22 -0
  79. metadata +146 -0
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestFarenheitConversionFactor < Test::Unit::TestCase
4
+
5
+ C21_AS_F = (BigDecimal("21") * BigDecimal("1.8")) + BigDecimal("32")
6
+ C22P7_AS_F = (BigDecimal("22.7") * BigDecimal("1.8")) + BigDecimal("32")
7
+
8
+ def setup
9
+ Weatherzone::Connection.connect("username", "password") do
10
+ "sekret" + Weatherzone::Connection.instance.password
11
+ end
12
+ Weatherzone::Connection.instance.stubs(:request).returns( File.open("test/response/everything.xml") )
13
+ weather = Weather.find_by_location_code("9770", :temperature_unit => "F")
14
+ country = weather.countries.first
15
+ location = country.locations.first
16
+ @forecast = location.forecasts.first
17
+ @conditions = location.conditions.first
18
+ end
19
+
20
+ def test_forecast_should_convert_and_round_min_temp_value_to_integer
21
+ assert_equal "#{C21_AS_F.round(0).to_i.to_s}", @forecast.temp_min_c_value
22
+ end
23
+
24
+ def test_forecast_should_convert_and_round_min_temp_value_with_units
25
+ assert_equal "#{C21_AS_F.round(0).to_i.to_s}°F", @forecast.temp_min_c
26
+ end
27
+
28
+ def test_forecast_should_convert_min_temp_units
29
+ assert_equal "°F", @forecast.temp_min_c_units
30
+ end
31
+
32
+ def test_conditions_should_convert_and_round_temp_value_to_one_decimal_place
33
+ assert_equal "#{C22P7_AS_F.round(1).to_s('f')}", @conditions.temp_c_value
34
+ end
35
+
36
+ def test_conditions_should_not_convert_rainfall_value
37
+ assert_equal "0.0", @conditions.rainfall_mm_value
38
+ end
39
+
40
+ def test_conditions_should_not_convert_rainfall_value_with_units
41
+ assert_equal "0.0mm", @conditions.rainfall_mm
42
+ end
43
+
44
+ def test_conditions_should_not_convert_rainfall_units
45
+ assert_equal "mm", @conditions.rainfall_mm_units
46
+ end
47
+
48
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestFinder < Test::Unit::TestCase
4
+
5
+ class SomeResource < Weatherzone::Resource
6
+ include Weatherzone::Finder
7
+ end
8
+
9
+ class DistrictResource < Weatherzone::Resource
10
+ include Weatherzone::Finder
11
+ elements :country, :as => :countries, :class => Country
12
+ end
13
+
14
+ def test_should_respond_to_find_by_location_code
15
+ assert SomeResource.respond_to?(:find_by_location_code)
16
+ end
17
+
18
+ def test_should_build_parameters
19
+ SomeResource.expects(:build_params).with(9770, :include => [:forecast])
20
+ SomeResource.find_by_location_code(9770, :include => [:forecast])
21
+ end
22
+
23
+ def test_should_make_request
24
+ Weatherzone::Connection.instance.expects(:request).returns( File.open("test/response/everything.xml") )
25
+ SomeResource.find_by_location_code(9770, :include => [:forecast])
26
+ end
27
+
28
+ def test_should_parse_response
29
+ f = File.open("test/response/everything.xml")
30
+ Weatherzone::Connection.instance.stubs(:request).returns( f )
31
+ SomeResource.expects(:parse).with(f)
32
+ SomeResource.find_by_location_code(9770, :include => [:forecast])
33
+ end
34
+
35
+ def test_should_find_by_location_name
36
+ SomeResource.expects(:build_params).with(nil, :params => "&lt=aploc&ln=Sydney%20NSW")
37
+ SomeResource.find_by_location_name("Sydney NSW")
38
+ end
39
+
40
+ def test_should_find_by_location_filter
41
+ SomeResource.expects(:build_params).with(nil, :params => "&lt=twcid&lf=twccapcity")
42
+ SomeResource.find_by_location_filter("twccapcity")
43
+ end
44
+
45
+ def test_should_find_by_district
46
+ SomeResource.expects(:build_params).with(nil, :params => "&lt=twcid&dist=N00")
47
+ SomeResource.find_by_district("N00")
48
+ end
49
+
50
+ def test_should_find_districts_by_state
51
+ DistrictResource.expects(:build_params).with(nil, :params => "&lt=dist&state=nsw")
52
+ DistrictResource.find_districts_by_state("nsw")
53
+ end
54
+
55
+ def test_should_find_using_arbitrary_include
56
+ SomeResource.expects(:build_params).with(nil, :include => [:moon_phases])
57
+ SomeResource.find(:include => [:moon_phases])
58
+ end
59
+
60
+ def test_should_include_location_parameter_string
61
+ assert_equal "&lc=9770", SomeResource.build_params(9770,{})
62
+ end
63
+
64
+ def test_should_include_forecasts
65
+ assert_equal "&lc=9770&fc=1", SomeResource.build_params(9770, :include => [:forecasts])
66
+ end
67
+
68
+ def test_should_include_point_forecasts
69
+ assert_equal "&lc=9770&fc=3", SomeResource.build_params(9770, :include => [:point_forecasts])
70
+ end
71
+
72
+ def test_should_include_district_forecasts
73
+ assert_equal "&lc=9770&dist_fc=1", SomeResource.build_params(9770, :include => [:district_forecasts])
74
+ end
75
+
76
+ def test_should_include_state_forecasts
77
+ assert_equal "&lc=9770&state_fc=1", SomeResource.build_params(9770, :include => [:state_forecasts])
78
+ end
79
+
80
+ def test_should_include_marine_forecasts
81
+ assert_equal "&lc=9770&marine=1", SomeResource.build_params(9770, :include => [:marine_forecast])
82
+ end
83
+
84
+ def test_should_include_tides
85
+ assert_equal "&lc=9770&tides=4", SomeResource.build_params(9770, :include => [:tides])
86
+ end
87
+
88
+ def test_should_include_tide_heights
89
+ assert_equal "&lc=9770&tideh=1", SomeResource.build_params(9770, :include => [:tide_height])
90
+ end
91
+
92
+ def test_should_include_buoy_observations
93
+ assert_equal "&lc=9770&buoy=1(period=24)", SomeResource.build_params(9770, :include => [:buoy_observations])
94
+ end
95
+
96
+ def test_should_include_conditions
97
+ assert_equal "&lc=9770&obs=1", SomeResource.build_params(9770, :include => [:conditions])
98
+ end
99
+
100
+ def test_should_include_warnings
101
+ assert_equal "&lc=9770&warn=2", SomeResource.build_params(9770, :include => [:warnings])
102
+ end
103
+
104
+ def test_should_include_uv_index
105
+ assert_equal "&lc=9770&uv=1", SomeResource.build_params(9770, :include => [:uv_index])
106
+ end
107
+
108
+ def test_should_include_sun
109
+ assert_equal "&lc=9770&fc_sun=2", SomeResource.build_params(9770, :include => [:sun])
110
+ end
111
+
112
+ def test_should_include_moon
113
+ assert_equal "&lc=9770&fc_moon=1", SomeResource.build_params(9770, :include => [:moon])
114
+ end
115
+
116
+ def test_should_include_historical_observations
117
+ assert_equal "&lc=9770&histobs=1", SomeResource.build_params(9770, :include => [:historical_observations])
118
+ end
119
+
120
+ def test_should_include_daily_observations
121
+ assert_equal "&lc=9770&dlyobs=7", SomeResource.build_params(9770, :include => [:daily_observations])
122
+ end
123
+
124
+ def test_should_include_climate_periods
125
+ assert_equal "&lc=9770&climate=1(months=12)", SomeResource.build_params(9770, :include => [:climate_periods])
126
+ end
127
+
128
+ def test_should_include_position
129
+ assert_equal "&lc=9770&latlon=1", SomeResource.build_params(9770, :include => [:position])
130
+ end
131
+
132
+ def test_should_include_surf_report
133
+ assert_equal "&lc=9770&surf_rpt=2", SomeResource.build_params(9770, :include => [:surf_report])
134
+ end
135
+
136
+ def test_should_include_moon_phases
137
+ assert_equal "&moon=1", SomeResource.build_params(nil, :include => [:moon_phases])
138
+ end
139
+
140
+ def test_should_include_news_items
141
+ assert_equal "&news=2", SomeResource.build_params(nil, :include => [:news_items])
142
+ end
143
+
144
+ def test_should_support_multiple_includes
145
+ assert_equal "&lc=9770&fc=1&obs=1", SomeResource.build_params(9770, :include => [:forecasts, :conditions])
146
+ end
147
+
148
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestForecast < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ location = country.locations.first
10
+ @forecast = location.forecasts.first
11
+ end
12
+
13
+ def test_should_be_a_forecast
14
+ assert_kind_of Forecast, @forecast
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:day_name, :date, :temp_min_c, :temp_max_c, :prob_precip, :icon,
19
+ :rain_range_text, :frost_risk_text, :uv, :first_light, :sunrise, :sunset, :last_light,
20
+ :moonrise, :moonset, :moon_phase_phase_text, :moon_phase_phase_num, :moon_phase_image_name,
21
+ :temp_min_c_units, :temp_max_c_units, :prob_precip_units, :uv_index, :icon_filename].each do |attr_name|
22
+ assert_not_nil @forecast.send(attr_name), "@forecast should respond to #{attr_name}"
23
+ end
24
+ end
25
+
26
+ def test_should_have_many_point_forecasts
27
+ assert @forecast.point_forecasts.any?
28
+ end
29
+
30
+ end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require 'logger'
5
+ require 'ruby-debug'
6
+
7
+ require File.dirname(__FILE__) + '/../lib/weatherzone'
8
+
9
+ require 'weatherzone/resources/point_forecast'
10
+ require 'weatherzone/resources/forecast'
11
+ require 'weatherzone/resources/conditions'
12
+ require 'weatherzone/resources/district_forecast'
13
+ require 'weatherzone/resources/state_forecast'
14
+ require 'weatherzone/resources/marine_summary'
15
+ require 'weatherzone/resources/marine_forecast'
16
+ require 'weatherzone/resources/surf_report'
17
+ require 'weatherzone/resources/lift'
18
+ require 'weatherzone/resources/snow_report'
19
+ require 'weatherzone/resources/historical_observation'
20
+ require 'weatherzone/resources/daily_observation'
21
+ require 'weatherzone/resources/climate_period'
22
+ require 'weatherzone/resources/warning'
23
+ require 'weatherzone/resources/image'
24
+ require 'weatherzone/resources/almanac_period'
25
+ require 'weatherzone/resources/almanac'
26
+ require 'weatherzone/resources/tide'
27
+ require 'weatherzone/resources/buoy_observation'
28
+ require 'weatherzone/resources/location'
29
+ require 'weatherzone/resources/country'
30
+ require 'weatherzone/resources/moon_phase'
31
+ require 'weatherzone/resources/news_item'
32
+ require 'weatherzone/resources/weather'
33
+
34
+ class Test::Unit::TestCase
35
+ def setup
36
+ Weatherzone::Connection.instance.stubs(:request).returns( File.open("test/response/everything.xml") )
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestHistoricalObservtion < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ location = country.locations.first
10
+ @historical_observation = location.historical_observations.first
11
+ end
12
+
13
+ def test_should_be_a_historical_observation
14
+ assert_kind_of HistoricalObservation, @historical_observation
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:obs_time_utc, :obs_time_local, :temp_c, :dp_c, :rh,
19
+ :wind_dir_degrees, :wind_dir_compass, :wind_speed_kph, :wind_speed_kts,
20
+ :wind_gust_kph, :wind_gust_kts, :feels_like_c, :rainfall_mm, :pressure_qnh_hpa].each do |attr_name|
21
+ assert_not_nil @historical_observation.send(attr_name), "@historical_observation should respond to #{attr_name}"
22
+ end
23
+ end
24
+
25
+ def test_should_have_units_attributes
26
+ [:temp_c, :dp_c, :rh, :wind_dir_degrees, :wind_speed_kph, :wind_speed_kts,
27
+ :wind_gust_kph, :wind_gust_kts, :feels_like_c, :pressure_qnh_hpa, :rainfall_mm].each do |attr_name|
28
+ assert_not_nil @historical_observation.send("#{attr_name}_units"), "@historical_observation should respond to #{attr_name}_units"
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestImage < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ location = country.locations.first
10
+ @image = location.synoptic_charts.first
11
+ end
12
+
13
+ def test_should_be_an_image
14
+ assert_kind_of Image, @image
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:issue_day_name, :issue_time_local, :valid_time, :text, :url].each do |attr_name|
19
+ assert_not_nil @image.send(attr_name), "@image should respond to #{attr_name}"
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestLocation < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ @location = country.locations.first
10
+ end
11
+
12
+ def test_should_be_a_location
13
+ assert_kind_of Location, @location
14
+ end
15
+
16
+ def test_should_not_have_nil_attributes
17
+ [:type, :code, :name, :state, :lat, :long, :elevation, :lat_units, :long_units, :elevation_units].each do |attr_name|
18
+ assert_not_nil @location.send(attr_name), "@location should respond to #{attr_name}"
19
+ end
20
+ end
21
+
22
+ def test_should_be_identifiable_by_code
23
+ assert_equal @location.id, @location.code
24
+ end
25
+
26
+ def test_should_have_forecasts
27
+ assert @location.forecasts.any?
28
+ end
29
+
30
+ def test_should_have_conditions
31
+ assert @location.conditions.any?
32
+ end
33
+
34
+ def test_should_have_district_forecasts
35
+ assert @location.district_forecasts.any?
36
+ end
37
+
38
+ def test_should_have_state_forecasts
39
+ assert @location.district_forecasts.any?
40
+ end
41
+
42
+ def test_should_have_historical_observations
43
+ assert @location.historical_observations.any?
44
+ end
45
+
46
+ def test_should_have_daily_observations
47
+ assert @location.daily_observations.any?
48
+ end
49
+
50
+ def test_should_have_warnings
51
+ assert @location.warnings.any?
52
+ end
53
+
54
+ def test_should_have_images
55
+ assert @location.synoptic_charts.any?
56
+ end
57
+
58
+ def test_should_have_almanacs
59
+ assert @location.almanacs.any?
60
+ end
61
+
62
+ def test_should_have_tides
63
+ assert @location.tides.any?
64
+ end
65
+
66
+ def test_should_have_buoy_observations
67
+ assert @location.buoy_observations.any?
68
+ end
69
+
70
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestMarineForecast < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ location = country.locations.first
10
+ @marine_forecast = location.marine_forecasts.first
11
+ end
12
+
13
+ def test_should_be_a_marine_forecast
14
+ assert_kind_of MarineForecast, @marine_forecast
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:issue_day_name, :issue_time_local, :short_text, :long_text, :sea_height_m, :sea_height_text, :swell_height_m, :swell_dir_compass].each do |attr_name|
19
+ assert_not_nil @marine_forecast.send(attr_name), "@marine_forecast should respond to #{attr_name}"
20
+ end
21
+ end
22
+
23
+ def test_should_have_marine_summaries
24
+ assert @marine_forecast.marine_summaries.any?
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestMarineSummary < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ weather = Weather.find_by_location_code("9770")
8
+ country = weather.countries.first
9
+ location = country.locations.first
10
+ @marine_forecast = location.marine_forecasts.first
11
+ @marine_summary = @marine_forecast.marine_summaries.first
12
+ end
13
+
14
+ def test_should_be_a_marine_summary
15
+ assert_kind_of MarineSummary, @marine_summary
16
+ end
17
+
18
+ def test_should_not_have_nil_attributes
19
+ [:day, :day_name, :precis, :wind_dir_compass, :wind_speed_kts, :wind_speed_kph, :wind_speed_kts_units, :wind_speed_kph_units].each do |attr_name|
20
+ assert_not_nil @marine_summary.send(attr_name), "@marine_summary should respond to #{attr_name}"
21
+ end
22
+ end
23
+
24
+ end