lib/barometer/services/google.rb in attack-barometer-0.3.1 vs lib/barometer/services/google.rb in attack-barometer-0.3.2
- old
+ new
@@ -38,10 +38,19 @@
def self.source_name
:google
end
+ # these are the icon codes that indicate "wet", used by wet? function
+ def self.wet_icon_codes
+ %w(rain chance_of_rain chance_of_storm thunderstorm mist)
+ end
+ # these are the icon codes that indicate "sun", used by sunny? function
+ def self.sunny_icon_codes
+ %w(sunny mostly_sunny partly_cloudy)
+ end
+
def self._measure(measurement, query, metric=true)
raise ArgumentError unless measurement.is_a?(Barometer::Measurement)
raise ArgumentError unless query.is_a?(Barometer::Query)
measurement.source = self.source_name
@@ -66,11 +75,14 @@
current.time = data['forecast_information']['current_date_time']['data']
end
if data['current_conditions']
data = data['current_conditions']
- current.icon = data['icon']['data'] if data['icon']
+ if data['icon']
+ icon_match = data['icon']['data'].match(/.*\/([A-Za-z_]*)\.png/)
+ current.icon = icon_match[1] if icon_match
+ end
current.condition = data['condition']['data'] if data['condition']
humidity_match = data['humidity']['data'].match(/[\d]+/)
current.humidity = humidity_match[0].to_i if humidity_match
@@ -98,10 +110,13 @@
# go through each forecast and create an instance
d = 0
data.each do |forecast|
forecast_measurement = ForecastMeasurement.new
- forecast_measurement.icon = forecast['icon']['data'] if forecast['icon']
+ if forecast['icon']
+ icon_match = forecast['icon']['data'].match(/.*\/([A-Za-z_]*)\.png/)
+ forecast_measurement.icon = icon_match[1] if icon_match
+ end
forecast_measurement.condition = forecast['condition']['data'] if forecast['condition']
if (start_date + d).strftime("%a").downcase == forecast['day_of_week']['data'].downcase
forecast_measurement.date = start_date + d
end
\ No newline at end of file