weather_report 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -2,3 +2,11 @@
2
2
 
3
3
  * 1 major enhancement:
4
4
  * Initial release
5
+
6
+ == 0.0.2 2009-07-16
7
+
8
+ * 4 bug fixes
9
+ * Added accessors for description on observation and description, advance_days, image_url on forecasts
10
+ * Change Backstage url string
11
+ * Throw a FormatException if there is no data from the Backstage service
12
+ * Added simple webpage
data/README.rdoc CHANGED
@@ -65,12 +65,14 @@ The full set of attributes is:
65
65
  londonWeather.observation.pressure_state
66
66
  londonWeather.observation.visibility
67
67
  londonWeather.observation.humidity
68
+ londonWeather.observation.description
68
69
 
69
70
  londonWeather.forecast.reading_date
70
71
  londonWeather.forecast.name
71
72
  londonWeather.forecast.country
72
73
  londonWeather.forecast.latitude
73
74
  londonWeather.forecast.longtitude
75
+ londonWeather.forecast.image_url
74
76
  londonWeather.forecast.for_today.date
75
77
  londonWeather.forecast.for_today.max_temperature
76
78
  londonWeather.forecast.for_today.min_temperature
@@ -80,10 +82,12 @@ The full set of attributes is:
80
82
  londonWeather.forecast.for_today.pressure
81
83
  londonWeather.forecast.for_today.visibility
82
84
  londonWeather.forecast.for_today.humidity
85
+ londonWeather.forecast.for_today.description
86
+ londonWeather.forecast.for_today.advance_days
83
87
 
84
88
  == REQUIREMENTS:
85
89
 
86
- The only external dependencies are REXML and net/http which are include as part of most Ruby installations.
90
+ The only external dependencies are REXML and net/http which are included as part of most Ruby installations.
87
91
 
88
92
  == INSTALL:
89
93
 
@@ -91,13 +95,13 @@ The weather_report library is distributed itself as a RubyGem and is available i
91
95
 
92
96
  sudo gem install weather_report
93
97
 
94
- Alternately, download the gem and install manually.
98
+ Alternately, download the gem here[http://www.cordinc.com/projects/weather_report/download/weather_report-0.0.2.gem] or the tgz here[http://www.cordinc.com/projects/weather_report/download/weather_report-0.0.2.tgz] and install manually.
95
99
 
96
100
  == LICENSE:
97
101
 
98
102
  (The MIT License)
99
103
 
100
- Copyright (c) 2009 FIXME full name
104
+ Copyright (c) 2009 Charles Cordingley
101
105
 
102
106
  Permission is hereby granted, free of charge, to any person obtaining
103
107
  a copy of this software and associated documentation files (the
@@ -7,7 +7,7 @@ $:.unshift(File.dirname(__FILE__)) unless
7
7
  # Class containing weather observations and forecasts for the location specified by id in the constructor.
8
8
  class WeatherReport
9
9
 
10
- VERSION = '0.0.1'
10
+ VERSION = '0.0.2'
11
11
 
12
12
  # The id is the number (1..9999) the BBC uses to identify cities for weather reports
13
13
  attr_reader :id
@@ -53,12 +53,12 @@ class WeatherReport
53
53
 
54
54
  # The url for getting current weather observations from BBC Backstage
55
55
  def observation_url()
56
- "http://news.bbc.co.uk/weather/forecast/#{@id}/ObservationsRSS.rss"
56
+ "http://newsrss.bbc.co.uk/weather/forecast/#{@id}/ObservationsRSS.xml"
57
57
  end
58
58
 
59
59
  # The url for getting weather forecasts from BBC Backstage
60
60
  def forecast_url()
61
- "http://news.bbc.co.uk/weather/forecast/#{@id}/Next3DaysRSS.rss"
61
+ "http://newsrss.bbc.co.uk/weather/forecast/#{@id}/Next3DaysRSS.xml"
62
62
  end
63
63
 
64
64
  end
@@ -90,7 +90,7 @@ class WeatherReportObservation
90
90
  DESCRIPTION = /Temperature: ([-\d\.]+|N\/A|NA|\(none\))(.+)Wind Direction: ([\w -\/\(\)]*), Wind Speed: ([-\d\.]+|N\/A|NA|\(none\))mph, Relative Humidity: ([\d\.]+|N\/A|NA|\(none\))(.*), Pressure: ([\d\.]+|N\/A|NA|\(none\))mB, ([\w -\/]+), Visibility: ([\w -\/]+)/
91
91
  SUMMARY = /(.+):(\W+)([\w -\/\(\)]+). (.+)/m
92
92
 
93
- attr_reader :temperature, :wind_direction, :wind_speed, :visibility, :pressure, :pressure_state, :humidity, :reading_date
93
+ attr_reader :temperature, :wind_direction, :wind_speed, :visibility, :pressure, :pressure_state, :humidity, :reading_date, :description
94
94
 
95
95
  # Constructs the weather observation from an XML string or file containing the XML in BBC Backstage weather format
96
96
  def initialize(document)
@@ -103,7 +103,9 @@ class WeatherReportObservation
103
103
  @description = md[3]
104
104
  }
105
105
 
106
+ hasDesc = false
106
107
  doc.elements.each("rss/channel/item[1]/description[1]") { |element|
108
+ hasDesc = true
107
109
  md = DESCRIPTION.match(element.text)
108
110
  @temperature = md[1].to_f
109
111
  @wind_direction = md[3]
@@ -113,6 +115,7 @@ class WeatherReportObservation
113
115
  @pressure_state = md[8]
114
116
  @visibility = md[9]
115
117
  }
118
+ raise WeatherReport::FormatError unless hasDesc
116
119
 
117
120
  rescue
118
121
  raise WeatherReport::FormatError
@@ -124,7 +127,7 @@ end
124
127
  class WeatherReportForecasts < Array
125
128
  include Location
126
129
 
127
- attr_reader :reading_date
130
+ attr_reader :reading_date, :image_url
128
131
 
129
132
  # Constructs the weather forecasts from an XML string or file containing the XML in BBC Backstage weather format
130
133
  def initialize(document)
@@ -137,6 +140,8 @@ class WeatherReportForecasts < Array
137
140
  self << WeatherReportForecast.new(element)
138
141
  }
139
142
 
143
+ raise WeatherReport::FormatError if length == 0
144
+
140
145
  rescue
141
146
  raise WeatherReport::FormatError
142
147
  end
@@ -178,16 +183,16 @@ class WeatherReportForecasts < Array
178
183
  SUMMARY = /([\w -\/]+): ([\w -]+|N\/A|NA|\(none\)), Max Temp: (.*)/m
179
184
  DESCRIPTION = /Max Temp: ([-\d\.]+|N\/A|NA|\(none\))(.+)Min Temp: ([-\d\.]+|N\/A|NA|\(none\))(.+)Wind Direction: ([\w -\/\(\)]*), Wind Speed: ([-\d\.]+|N\/A|NA|\(none\))mph, Visibility: ([\w -\/]+), Pressure: ([\d\.]+|N\/A|NA|\(none\))mB, Humidity: ([\d\.]+|N\/A|NA|\(none\))(.*), (.+)/m
180
185
 
181
- attr_reader :max_temperature, :min_temperature, :wind_direction, :wind_speed, :visibility, :pressure, :humidity, :date
186
+ attr_reader :max_temperature, :min_temperature, :wind_direction, :wind_speed, :visibility, :pressure, :humidity, :date, :description, :advance_days
182
187
 
183
188
  # Constructs the single day forecast from an REXML element containing the forecast in BBC Backstage weather format
184
189
  def initialize(item)
185
190
  item.elements.each("title[1]") { |element|
186
191
  md = SUMMARY.match(element.text)
187
192
  @description = md[2]
188
- diff = day_diff(md[1])
189
- raise(WeatherReport::FormatError, "WeatherReport Error: Day mismatch.") if diff.nil?
190
- @date = Date.today+diff
193
+ @advance_days = day_diff(md[1])
194
+ raise(WeatherReport::FormatError, "WeatherReport Error: Day mismatch.") if @advance_days.nil?
195
+ @date = Date.today+@advance_days
191
196
  }
192
197
 
193
198
  item.elements.each("description[1]") { |element|
@@ -51,6 +51,14 @@ class TestWeatherReport < Test::Unit::TestCase
51
51
  assert_raise(WeatherReport::FormatError) { WeatherReportForecasts.new(File.read(File.dirname(__FILE__) + '/error.rss'))}
52
52
  end
53
53
 
54
+ def test_moved_forecast
55
+ assert_raise(WeatherReport::FormatError) { WeatherReportForecasts.new(File.read(File.dirname(__FILE__) + '/moved.rss'))}
56
+ end
57
+
58
+ def test_moved_observation
59
+ assert_raise(WeatherReport::FormatError) { WeatherReportObservation.new(File.read(File.dirname(__FILE__) + '/moved.rss'))}
60
+ end
61
+
54
62
  def test_current_forecast
55
63
  doc = File.read(File.dirname(__FILE__) + '/BBC_Next3DaysRSS.rss')
56
64
  doc = doc.gsub("<TODAY>", Date::DAYNAMES[Date.today.wday]).gsub("<TOMORROW>", Date::DAYNAMES[(Date.today+1).wday]).gsub("<DAY_AFTER_TOMORROW>", Date::DAYNAMES[(Date.today+2).wday])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Cordingley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-10 00:00:00 +01:00
12
+ date: 2009-07-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency