weatherzone 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
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,9 @@
1
+ class MarineForecast < Weatherzone::Resource
2
+ include Weatherzone::Helpers::Units
3
+
4
+ has_elements :issue_day_name, :issue_time_local, :short_text, :long_text, :sea_height_m, :sea_height_text, :swell_height_m, :swell_dir_compass
5
+ has_attribute :units, :on_elements => [:sea_height_m, :swell_height_m]
6
+ value_plus_unit_readers :sea_height_m, :swell_height_m
7
+
8
+ elements :marine_summary, :as => :marine_summaries, :class => MarineSummary
9
+ end
@@ -0,0 +1,8 @@
1
+ class MarineSummary < Weatherzone::Resource
2
+ include Weatherzone::Helpers::Units
3
+
4
+ attributes :day
5
+ has_elements :day, :day_name, :precis, :wind_dir_compass, :wind_speed_kts, :wind_speed_kph
6
+ has_attribute :units, :on_elements => [:wind_speed_kts, :wind_speed_kph]
7
+ value_plus_unit_readers :wind_speed_kts, :wind_speed_kph
8
+ end
@@ -0,0 +1,23 @@
1
+ class MoonPhase < Weatherzone::Resource
2
+ attributes :day
3
+ has_elements :day_name, :date, :moon_phase
4
+ has_attribute :phase_num, :on_elements => :moon_phase
5
+ has_attribute :phase_text, :on_elements => :moon_phase
6
+ has_attribute :image_name, :on_elements => :moon_phase
7
+
8
+ PHASE_TEXT_TRANSLATIONS = {
9
+ "1st quarter" => "First quarter",
10
+ "Full moon" => "Full moon",
11
+ "3rd quarter" => "Last quarter",
12
+ "New moon" => "New moon"
13
+ }
14
+
15
+ def date
16
+ Date.parse(@date)
17
+ end
18
+
19
+ def phase_text
20
+ PHASE_TEXT_TRANSLATIONS[moon_phase_phase_text]
21
+ end
22
+
23
+ end
@@ -0,0 +1,18 @@
1
+ class NewsItem < Weatherzone::Resource
2
+
3
+ include Weatherzone::Helpers::DateParser
4
+
5
+ attributes :item_num, :source
6
+ has_elements :link, :title, :byline, :dateline, :creditline, :copyright, :text
7
+ has_attribute :type, :on_elements => :link
8
+ has_attribute :description, :on_elements => :link
9
+ has_attribute :url, :on_elements => :link
10
+ has_attribute :date, :on_elements => [:dateline, :copyright]
11
+
12
+ interpret_as_date :dateline_date
13
+
14
+ def copyright_line
15
+ "&copy; #{copyright} #{copyright_date}"
16
+ end
17
+
18
+ end
@@ -0,0 +1,40 @@
1
+ class PointForecast < Weatherzone::Resource
2
+ attributes :time
3
+ has_elements :dp_c, :rh, :wind_dir_degrees, :wind_dir_compass, :wind_speed_kph
4
+ has_attribute :units, :on_elements => [:dp_c, :rh, :wind_dir_degrees, :wind_speed_kph]
5
+
6
+ WIND_DIRECTIONS = {
7
+ :N => "North",
8
+ :NNE => "North North East",
9
+ :NE => "North East",
10
+ :ENE => "East North East",
11
+ :E => "East",
12
+ :ESE => "East South East",
13
+ :SE => "South East",
14
+ :SSE => "South South East",
15
+ :S => "South",
16
+ :SSW => "South South West",
17
+ :SW => "South West",
18
+ :WSW => "West South West",
19
+ :W => "West",
20
+ :WNW => "West North West",
21
+ :NW => "North West",
22
+ :NNW => "North North West"
23
+ }
24
+
25
+ def meridian_indicator
26
+ Time.parse(self.time).strftime("%p").downcase
27
+ end
28
+
29
+ def wind_dir_compass_long
30
+ WIND_DIRECTIONS[self.wind_dir_compass.to_sym] if self.wind_dir_compass
31
+ end
32
+
33
+ def relative_humidity
34
+ self.rh ? "#{self.rh}#{self.rh_units}" : "n/a"
35
+ end
36
+
37
+ def dew_point
38
+ self.dp_c ? "#{self.dp_c}#{self.dp_c_units}" : "n/a"
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ class SnowReport < Weatherzone::Resource
2
+ has_elements :day_name, :issue_time_local, :visibility_text, :road_conditions, :primary_surface, :snow_conditions, :snow_cover, :snow_depth_avg_cm, :snow_depth_new_cm,
3
+ :snow_making, :grooming, :last_snowfall_date, :resort_summary, :lifts_open
4
+ elements :lift, :as => :lifts, :class => Lift
5
+ end
@@ -0,0 +1,4 @@
1
+ class StateForecast < Weatherzone::Resource
2
+ attributes :period
3
+ has_elements :period_name, :precis
4
+ end
@@ -0,0 +1,5 @@
1
+ class SurfReport < Weatherzone::Resource
2
+ has_elements :issue_day_name, :issue_time_local, :report_day_name, :report_time_local, :surf_summary_text, :wind_text, :weather_text, :summary
3
+
4
+ element :image, :value => :url, :as => :image_url
5
+ end
@@ -0,0 +1,9 @@
1
+ class Tide < Weatherzone::Resource
2
+ include Weatherzone::Helpers::Units
3
+ include Weatherzone::Helpers::DateParser
4
+
5
+ has_elements :day_name, :time, :tide_type, :tide_height_m
6
+ has_attribute :units, :on_elements => [:tide_height_m]
7
+ value_plus_unit_readers :tide_height_m
8
+ interpret_as_time :time
9
+ end
@@ -0,0 +1,21 @@
1
+ class Warning < Weatherzone::Resource
2
+
3
+ include Weatherzone::Helpers::DateParser
4
+
5
+ attributes :id, :type
6
+ has_elements :issue_day_name, :issue_time_local, :expire_time_local, :short_text, :long_text, :url
7
+
8
+ interpret_as_time :issue_time_local, :expire_time_local
9
+
10
+ # Override id and type
11
+ attr_reader :id, :type
12
+
13
+ def hash
14
+ id.hash
15
+ end
16
+
17
+ def eql?(other)
18
+ self.id == other.id
19
+ end
20
+
21
+ end
@@ -0,0 +1,14 @@
1
+ class Weather < Weatherzone::Resource
2
+ include Weatherzone::Finder
3
+ elements :country, :as => :countries, :class => Country
4
+ elements :astro_element, :as => :moon_phases, :class => MoonPhase
5
+ elements :news_item, :as => :news_items, :class => NewsItem
6
+
7
+ def first_location
8
+ countries.first.locations.first
9
+ end
10
+
11
+ def has_locations?
12
+ countries.any? && countries.first.locations.any?
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestAlmanac < Test::Unit::TestCase
4
+ def setup
5
+ super
6
+ weather = Weather.find_by_location_code("9770")
7
+ country = weather.countries.first
8
+ location = country.locations.first
9
+ @almanac = location.almanacs.first
10
+ end
11
+
12
+ def test_should_be_a_almanac
13
+ assert_kind_of Almanac, @almanac
14
+ end
15
+
16
+ def test_should_not_have_nil_attributes
17
+ [:month_num, :month_name, :date_start, :date_end].each do |attr_name|
18
+ assert_not_nil @almanac.send(attr_name), "@almanac should respond to #{attr_name}"
19
+ end
20
+ end
21
+
22
+ def test_should_have_many_almanac_periods
23
+ assert @almanac.almanac_periods.any?
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestAlmanacPeriod < 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
+ almanac = location.almanacs.first
11
+ @almanac_period = almanac.almanac_periods.first
12
+ end
13
+
14
+ def test_should_be_a_almanac_period
15
+ assert_kind_of AlmanacPeriod, @almanac_period
16
+ end
17
+
18
+ def test_should_not_have_nil_attributes
19
+ [:code, :title, :month_name, :from, :to].each do |attr_name|
20
+ assert_not_nil @almanac_period.send(attr_name), "@almanac_period should respond to #{attr_name}"
21
+ end
22
+ end
23
+
24
+ def test_should_have_accessors_for_attributes_setup_with_the_almanac_element_helper
25
+ # Just testing a representative sample as there are 80 odd accessors that get added to the AlmanacPeriod resource in this way
26
+ [:avg_rainfall_this_month, :avg_rainfall_this_month_value, :avg_rainfall_this_month_units, :avg_rainfall_this_month_days,
27
+ :avg_rainfall_this_year, :avg_rainfall_this_year_value, :avg_rainfall_this_year_units, :avg_rainfall_this_year_days].each do |attr_name|
28
+ assert @almanac_period.respond_to?(attr_name), "@almanac_period should respond to #{attr_name}"
29
+ assert @almanac_period.respond_to?("#{attr_name}="), "@almanac_period should respond to #{attr_name}="
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestBuoyObservation < 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
+ @buoy_observation = location.buoy_observations.first
11
+ end
12
+
13
+ def test_should_be_a_tide
14
+ assert_kind_of BuoyObservation, @buoy_observation
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:day_name, :time, :wave_height_m_significant, :wave_height_m_max, :wave_height_m_units, :wave_height_ft_significant, :wave_height_ft_max, :wave_height_ft_units,
19
+ :wave_period_significant, :wave_period_peak, :wave_period_units, :wave_dir_degrees, :wave_dir_degrees_units, :wave_dir_compass, :sea_temp_c, :sea_temp_c_units].each do |attr_name|
20
+ assert_not_nil @buoy_observation.send(attr_name), "@buoy_observation should respond to #{attr_name}"
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestClimatePeriod < 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
+ @climate_period = location.climate_periods.first
11
+ end
12
+
13
+ def test_should_be_a_climate_period
14
+ assert_kind_of ClimatePeriod, @climate_period
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:name, :mean_temp_min_c, :mean_temp_max_c, :rain_days, :mean_rainfall_mm].each do |attr_name|
19
+ assert_not_nil @climate_period.send(attr_name), "@climate_period should respond to #{attr_name}"
20
+ end
21
+ end
22
+
23
+ def test_should_have_units_attributes
24
+ [:mean_temp_min_c, :mean_temp_max_c, :mean_rainfall_mm].each do |attr_name|
25
+ assert_not_nil @climate_period.send("#{attr_name}_units"), "@climate_period should respond to #{attr_name}_units"
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestConditions < 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
+ @conditions = location.conditions.first
11
+ end
12
+
13
+ def test_should_be_a_conditions
14
+ assert_kind_of Conditions, @conditions
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 @conditions.send(attr_name), "@conditions 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 @conditions.send("#{attr_name}_units"), "@conditions should respond to #{attr_name}_units"
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestConnection < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Weatherzone::Connection.connect("username", "password", :url => "http://ws1.theweather.com.au/") do
7
+ "sekret" + Weatherzone::Connection.instance.password
8
+ end
9
+ @connection = Weatherzone::Connection.instance
10
+ end
11
+
12
+ def test_should_set_username
13
+ assert_equal "username", @connection.username
14
+ end
15
+
16
+ def test_should_set_password
17
+ assert_equal "password", @connection.password
18
+ end
19
+
20
+ def test_should_set_key
21
+ assert_equal "sekretpassword", @connection.key
22
+ end
23
+
24
+ def test_should_provide_base_url
25
+ assert_equal "http://ws1.theweather.com.au/?u=username&k=sekretpassword", @connection.base_url
26
+ end
27
+
28
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestCountry < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Weatherzone::Connection.instance.stubs(:request).returns( File.open("test/response/everything.xml") )
7
+ weather = Weather.find_by_location_code("9770")
8
+ @country = weather.countries.first
9
+ end
10
+
11
+ def test_should_be_a_country
12
+ assert_kind_of Country, @country
13
+ end
14
+
15
+ def test_should_not_have_nil_attributes
16
+ [:code, :name].each do |attr_name|
17
+ assert @country.send(attr_name), "@country should respond to #{attr_name}"
18
+ end
19
+ end
20
+
21
+ def test_should_have_locations
22
+ assert @country.locations.any?
23
+ end
24
+
25
+ def test_locations_should_be_locations
26
+ assert_kind_of Location, @country.locations.first
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestDailyObservtion < 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
+ @daily_observation = location.daily_observations.first
11
+ end
12
+
13
+ def test_should_be_a_daily_observation
14
+ assert_kind_of DailyObservation, @daily_observation
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:day_name, :date, :temp_min_c, :temp_max_c, :rainfall_mm].each do |attr_name|
19
+ assert_not_nil @daily_observation.send(attr_name), "@daily_observation should respond to #{attr_name}"
20
+ end
21
+ end
22
+
23
+ def test_should_have_units_attributes
24
+ [:temp_min_c, :temp_max_c, :rainfall_mm].each do |attr_name|
25
+ assert_not_nil @daily_observation.send("#{attr_name}_units"), "@daily_observation should respond to #{attr_name}_units"
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestDistrictForecast < 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
+ @district_forecast = location.district_forecasts.first
11
+ end
12
+
13
+ def test_should_be_a_district_forecast
14
+ assert_kind_of DistrictForecast, @district_forecast
15
+ end
16
+
17
+ def test_should_not_have_nil_attributes
18
+ [:period, :period_name, :precis, :icon, :icon_filename].each do |attr_name|
19
+ assert_not_nil @district_forecast.send(attr_name), "@district_forecast should respond to #{attr_name}"
20
+ end
21
+ end
22
+
23
+ end