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
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-11-02
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,51 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/weatherzone
6
+ lib/ext/class.rb
7
+ lib/ext/object.rb
8
+ lib/weatherzone.rb
9
+ lib/weatherzone/connection.rb
10
+ lib/weatherzone/resource.rb
11
+ lib/weatherzone/finder.rb
12
+ lib/weatherzone/helpers/almanac_element.rb
13
+ lib/weatherzone/helpers/date_parser.rb
14
+ lib/weatherzone/helpers/units.rb
15
+ lib/weatherzone/resources/almanac.rb
16
+ lib/weatherzone/resources/almanac_period.rb
17
+ lib/weatherzone/resources/conditions.rb
18
+ lib/weatherzone/resources/country.rb
19
+ lib/weatherzone/resources/daily_observation.rb
20
+ lib/weatherzone/resources/district_forecast.rb
21
+ lib/weatherzone/resources/forecast.rb
22
+ lib/weatherzone/resources/historical_observation.rb
23
+ lib/weatherzone/resources/climate_period.rb
24
+ lib/weatherzone/resources/image.rb
25
+ lib/weatherzone/resources/tide.rb
26
+ lib/weatherzone/resources/location.rb
27
+ lib/weatherzone/resources/moon_phase.rb
28
+ lib/weatherzone/resources/news_item.rb
29
+ lib/weatherzone/resources/point_forecast.rb
30
+ lib/weatherzone/resources/state_forecast.rb
31
+ lib/weatherzone/resources/marine_forecast.rb
32
+ lib/weatherzone/resources/marine_summary.rb
33
+ lib/weatherzone/resources/lift.rb
34
+ lib/weatherzone/resources/snow_report.rb
35
+ lib/weatherzone/resources/surf_report.rb
36
+ lib/weatherzone/resources/warning.rb
37
+ lib/weatherzone/resources/weather.rb
38
+ lib/vendor/openuri_memcached/History.txt
39
+ lib/vendor/openuri_memcached/License.txt
40
+ lib/vendor/openuri_memcached/README.markdown
41
+ lib/vendor/openuri_memcached/lib/openuri_memcached.rb
42
+ lib/vendor/openuri_memcached/lib/openuri/common.rb
43
+ lib/vendor/openuri_memcached/lib/openuri/memcached.rb
44
+ lib/vendor/openuri_memcached/lib/openuri/rails-cache.rb
45
+ lib/tzinfo/definitions/Australia/CDT.rb
46
+ lib/tzinfo/definitions/Australia/CST.rb
47
+ lib/tzinfo/definitions/Australia/EDT.rb
48
+ lib/tzinfo/definitions/Australia/EST.rb
49
+ lib/tzinfo/definitions/Australia/WDT.rb
50
+ lib/tzinfo/definitions/Australia/WST.rb
51
+ lib/weatherzone/helpers/date_parser.rb
data/README.txt ADDED
@@ -0,0 +1,30 @@
1
+ = weatherzone
2
+
3
+ http://github.com/benaskins/weatherzone/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby client for the weatherzone webservice.
8
+
9
+ == LICENSE:
10
+
11
+ Copyright (c) 2008 FIX
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining
14
+ a copy of this software and associated documentation files (the
15
+ 'Software'), to deal in the Software without restriction, including
16
+ without limitation the rights to use, copy, modify, merge, publish,
17
+ distribute, sublicense, and/or sell copies of the Software, and to
18
+ permit persons to whom the Software is furnished to do so, subject to
19
+ the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be
22
+ included in all copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require './lib/weatherzone.rb'
4
+
5
+ Hoe.new('weatherzone', Weatherzone::VERSION) do |p|
6
+ p.developer('Ben Askins', 'ben.askins@gmail.com')
7
+ end
data/bin/weatherzone ADDED
File without changes
data/lib/ext/class.rb ADDED
@@ -0,0 +1,175 @@
1
+ # Copyright (c) 2004-2008 David Heinemeier Hansson
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # Allows attributes to be shared within an inheritance hierarchy, but where
23
+ # each descendant gets a copy of their parents' attributes, instead of just a
24
+ # pointer to the same. This means that the child can add elements to, for
25
+ # example, an array without those additions being shared with either their
26
+ # parent, siblings, or children, which is unlike the regular class-level
27
+ # attributes that are shared across the entire hierarchy.
28
+ class Class
29
+ # Defines class-level and instance-level attribute reader.
30
+ #
31
+ # @param *syms<Array> Array of attributes to define reader for.
32
+ # @return <Array[#to_s]> List of attributes that were made into cattr_readers
33
+ #
34
+ # @api public
35
+ #
36
+ # @todo Is this inconsistent in that it does not allow you to prevent
37
+ # an instance_reader via :instance_reader => false
38
+ def cattr_reader(*syms)
39
+ syms.flatten.each do |sym|
40
+ next if sym.is_a?(Hash)
41
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
42
+ unless defined? @@#{sym}
43
+ @@#{sym} = nil
44
+ end
45
+
46
+ def self.#{sym}
47
+ @@#{sym}
48
+ end
49
+
50
+ def #{sym}
51
+ @@#{sym}
52
+ end
53
+ RUBY
54
+ end
55
+ end
56
+
57
+ # Defines class-level (and optionally instance-level) attribute writer.
58
+ #
59
+ # @param <Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define writer for.
60
+ # @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
61
+ # @return <Array[#to_s]> List of attributes that were made into cattr_writers
62
+ #
63
+ # @api public
64
+ def cattr_writer(*syms)
65
+ options = syms.last.is_a?(Hash) ? syms.pop : {}
66
+ syms.flatten.each do |sym|
67
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
68
+ unless defined? @@#{sym}
69
+ @@#{sym} = nil
70
+ end
71
+
72
+ def self.#{sym}=(obj)
73
+ @@#{sym} = obj
74
+ end
75
+ RUBY
76
+
77
+ unless options[:instance_writer] == false
78
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
79
+ def #{sym}=(obj)
80
+ @@#{sym} = obj
81
+ end
82
+ RUBY
83
+ end
84
+ end
85
+ end
86
+
87
+ # Defines class-level (and optionally instance-level) attribute accessor.
88
+ #
89
+ # @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define accessor for.
90
+ # @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
91
+ # @return <Array[#to_s]> List of attributes that were made into accessors
92
+ #
93
+ # @api public
94
+ def cattr_accessor(*syms)
95
+ cattr_reader(*syms)
96
+ cattr_writer(*syms)
97
+ end
98
+
99
+ # Defines class-level inheritable attribute reader. Attributes are available to subclasses,
100
+ # each subclass has a copy of parent's attribute.
101
+ #
102
+ # @param *syms<Array[#to_s]> Array of attributes to define inheritable reader for.
103
+ # @return <Array[#to_s]> Array of attributes converted into inheritable_readers.
104
+ #
105
+ # @api public
106
+ #
107
+ # @todo Do we want to block instance_reader via :instance_reader => false
108
+ # @todo It would be preferable that we do something with a Hash passed in
109
+ # (error out or do the same as other methods above) instead of silently
110
+ # moving on). In particular, this makes the return value of this function
111
+ # less useful.
112
+ def class_inheritable_reader(*ivars)
113
+ instance_reader = ivars.pop[:reader] if ivars.last.is_a?(Hash)
114
+
115
+ ivars.each do |ivar|
116
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
117
+ def self.#{ivar}
118
+ return @#{ivar} if self.object_id == #{self.object_id} || defined?(@#{ivar})
119
+ ivar = superclass.#{ivar}
120
+ return nil if ivar.nil? && !#{self}.instance_variable_defined?("@#{ivar}")
121
+ @#{ivar} = ivar.try_dup
122
+ end
123
+ RUBY
124
+ unless instance_reader == false
125
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
126
+ def #{ivar}
127
+ self.class.#{ivar}
128
+ end
129
+ RUBY
130
+ end
131
+ end
132
+ end
133
+
134
+ # Defines class-level inheritable attribute writer. Attributes are available to subclasses,
135
+ # each subclass has a copy of parent's attribute.
136
+ #
137
+ # @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
138
+ # define inheritable writer for.
139
+ # @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
140
+ # @return <Array[#to_s]> An Array of the attributes that were made into inheritable writers.
141
+ #
142
+ # @api public
143
+ #
144
+ # @todo We need a style for class_eval <<-HEREDOC. I'd like to make it
145
+ # class_eval(<<-RUBY, __FILE__, __LINE__), but we should codify it somewhere.
146
+ def class_inheritable_writer(*ivars)
147
+ instance_writer = ivars.pop[:instance_writer] if ivars.last.is_a?(Hash)
148
+ ivars.each do |ivar|
149
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
150
+ def self.#{ivar}=(obj)
151
+ @#{ivar} = obj
152
+ end
153
+ RUBY
154
+ unless instance_writer == false
155
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
156
+ def #{ivar}=(obj) self.class.#{ivar} = obj end
157
+ RUBY
158
+ end
159
+ end
160
+ end
161
+
162
+ # Defines class-level inheritable attribute accessor. Attributes are available to subclasses,
163
+ # each subclass has a copy of parent's attribute.
164
+ #
165
+ # @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
166
+ # define inheritable accessor for.
167
+ # @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
168
+ # @return <Array[#to_s]> An Array of attributes turned into inheritable accessors.
169
+ #
170
+ # @api public
171
+ def class_inheritable_accessor(*syms)
172
+ class_inheritable_reader(*syms)
173
+ class_inheritable_writer(*syms)
174
+ end
175
+ end
data/lib/ext/object.rb ADDED
@@ -0,0 +1,74 @@
1
+ class Object
2
+ # Available in 1.8.6 and later.
3
+ unless respond_to?(:instance_variable_defined?)
4
+ def instance_variable_defined?(variable)
5
+ instance_variables.include?(variable.to_s)
6
+ end
7
+ end
8
+
9
+ # Returns a hash that maps instance variable names without "@" to their
10
+ # corresponding values. Keys are strings both in Ruby 1.8 and 1.9.
11
+ #
12
+ # class C
13
+ # def initialize(x, y)
14
+ # @x, @y = x, y
15
+ # end
16
+ # end
17
+ #
18
+ # C.new(0, 1).instance_values # => {"x" => 0, "y" => 1}
19
+ def instance_values #:nodoc:
20
+ instance_variables.inject({}) do |values, name|
21
+ values[name.to_s[1..-1]] = instance_variable_get(name)
22
+ values
23
+ end
24
+ end
25
+
26
+ # Returns an array of instance variable names including "@". They are strings
27
+ # both in Ruby 1.8 and 1.9.
28
+ #
29
+ # class C
30
+ # def initialize(x, y)
31
+ # @x, @y = x, y
32
+ # end
33
+ # end
34
+ #
35
+ # C.new(0, 1).instance_variable_names # => ["@y", "@x"]
36
+ if RUBY_VERSION >= '1.9'
37
+ def instance_variable_names
38
+ instance_variables.map { |var| var.to_s }
39
+ end
40
+ else
41
+ alias_method :instance_variable_names, :instance_variables
42
+ end
43
+
44
+ # Copies the instance variables of +object+ into +self+.
45
+ #
46
+ # Instance variable names in the +exclude+ array are ignored. If +object+
47
+ # responds to <tt>protected_instance_variables</tt> the ones returned are
48
+ # also ignored. For example, Rails controllers implement that method.
49
+ #
50
+ # In both cases strings and symbols are understood, and they have to include
51
+ # the at sign.
52
+ #
53
+ # class C
54
+ # def initialize(x, y, z)
55
+ # @x, @y, @z = x, y, z
56
+ # end
57
+ #
58
+ # def protected_instance_variables
59
+ # %w(@z)
60
+ # end
61
+ # end
62
+ #
63
+ # a = C.new(0, 1, 2)
64
+ # b = C.new(3, 4, 5)
65
+ #
66
+ # a.copy_instance_variables_from(b, [:@y])
67
+ # # a is now: @x = 3, @y = 1, @z = 2
68
+ def copy_instance_variables_from(object, exclude = []) #:nodoc:
69
+ exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
70
+
71
+ vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
72
+ vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module CDT
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/CDT', 'Australia/Adelaide'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module CST
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/CST', 'Australia/Darwin'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module EDT
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/EDT', 'Australia/Sydney'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module EST
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/EST', 'Australia/Brisbane'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module WDT
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/WDT', 'Australia/Perth'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo/timezone_definition'
2
+
3
+ module TZInfo
4
+ module Definitions
5
+ module Australia
6
+ module WST
7
+ include TimezoneDefinition
8
+
9
+ linked_timezone 'Australia/WST', 'Australia/Perth'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ == 0.2.0 2009-01-23
2
+ * Include support for Rails.cache
3
+
4
+ == 0.1.0 2008-04-17
5
+ * Included Evan Weaver's Memcached C wrapper for a healthy speed improvement
6
+
7
+ == 0.0.3 2008-01-18
8
+ * Caches are now stored by the uri as the key like they originally were
9
+
10
+ == 0.0.2 2008-01-15
11
+ * Some moron forgot to write the dependency list correctly for 0.0.1
12
+
13
+
14
+ == 0.0.1 2008-01-14
15
+
16
+ * Inital release:
17
+ * Proof of concept come used library for a personal project
18
+