barometer 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +78 -70
- data/VERSION.yml +2 -2
- data/bin/barometer +100 -37
- data/lib/barometer.rb +12 -8
- data/lib/barometer/base.rb +48 -20
- data/lib/barometer/data.rb +5 -1
- data/lib/barometer/data/current.rb +23 -15
- data/lib/barometer/data/distance.rb +15 -5
- data/lib/barometer/data/forecast.rb +23 -5
- data/lib/barometer/data/geo.rb +16 -54
- data/lib/barometer/data/local_datetime.rb +137 -0
- data/lib/barometer/data/local_time.rb +134 -0
- data/lib/barometer/data/location.rb +6 -1
- data/lib/barometer/data/measurement.rb +71 -42
- data/lib/barometer/data/night.rb +69 -0
- data/lib/barometer/data/pressure.rb +15 -5
- data/lib/barometer/data/speed.rb +16 -5
- data/lib/barometer/data/sun.rb +8 -20
- data/lib/barometer/data/temperature.rb +22 -9
- data/lib/barometer/data/units.rb +10 -19
- data/lib/barometer/data/zone.rb +135 -9
- data/lib/barometer/formats.rb +12 -0
- data/lib/barometer/formats/coordinates.rb +42 -0
- data/lib/barometer/formats/format.rb +46 -0
- data/lib/barometer/formats/geocode.rb +51 -0
- data/lib/barometer/formats/icao.rb +37 -0
- data/lib/barometer/formats/postalcode.rb +22 -0
- data/lib/barometer/formats/short_zipcode.rb +17 -0
- data/lib/barometer/formats/weather_id.rb +107 -0
- data/lib/barometer/formats/zipcode.rb +31 -0
- data/lib/barometer/query.rb +61 -232
- data/lib/barometer/services.rb +14 -4
- data/lib/barometer/translations/icao_country_codes.yml +9 -0
- data/lib/barometer/translations/weather_country_codes.yml +17 -0
- data/lib/barometer/weather.rb +51 -30
- data/lib/barometer/{services → weather_services}/google.rb +23 -26
- data/lib/barometer/weather_services/noaa.rb +6 -0
- data/lib/barometer/{services → weather_services}/service.rb +101 -92
- data/lib/barometer/weather_services/weather_bug.rb +6 -0
- data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
- data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
- data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
- data/lib/barometer/web_services/geocode.rb +33 -0
- data/lib/barometer/web_services/weather_id.rb +37 -0
- data/lib/barometer/web_services/web_service.rb +32 -0
- data/lib/demometer/demometer.rb +31 -4
- data/lib/demometer/views/forecast.erb +20 -0
- data/lib/demometer/views/index.erb +10 -3
- data/lib/demometer/views/measurement.erb +8 -3
- data/lib/demometer/views/readme.erb +63 -24
- data/spec/barometer_spec.rb +18 -36
- data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
- data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
- data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
- data/spec/data/geo_spec.rb +91 -0
- data/spec/data/local_datetime_spec.rb +269 -0
- data/spec/data/local_time_spec.rb +239 -0
- data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
- data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
- data/spec/data/night_measurement_spec.rb +136 -0
- data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
- data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
- data/spec/data/sun_spec.rb +49 -0
- data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
- data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
- data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
- data/spec/fixtures/formats/weather_id/90210.xml +1 -0
- data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
- data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
- data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
- data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
- data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
- data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
- data/spec/fixtures/geocode/atlanta.xml +1 -0
- data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
- data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
- data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
- data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
- data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
- data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
- data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
- data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
- data/spec/formats/coordinates_spec.rb +158 -0
- data/spec/formats/format_spec.rb +73 -0
- data/spec/formats/geocode_spec.rb +179 -0
- data/spec/formats/icao_spec.rb +61 -0
- data/spec/formats/postalcode_spec.rb +59 -0
- data/spec/formats/short_zipcode_spec.rb +53 -0
- data/spec/formats/weather_id_spec.rb +191 -0
- data/spec/formats/zipcode_spec.rb +111 -0
- data/spec/query_spec.rb +261 -288
- data/spec/spec_helper.rb +128 -4
- data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
- data/spec/weather_services/services_spec.rb +1118 -0
- data/spec/weather_services/weather_dot_com_spec.rb +327 -0
- data/spec/weather_services/wunderground_spec.rb +332 -0
- data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
- data/spec/weather_spec.rb +73 -61
- data/spec/web_services/geocode_spec.rb +45 -0
- data/spec/web_services/web_services_spec.rb +26 -0
- metadata +88 -36
- data/lib/barometer/services/noaa.rb +0 -6
- data/lib/barometer/services/weather_bug.rb +0 -6
- data/lib/barometer/services/weather_dot_com.rb +0 -6
- data/spec/data_geo_spec.rb +0 -94
- data/spec/data_sun_spec.rb +0 -76
- data/spec/service_wunderground_spec.rb +0 -330
- data/spec/services_spec.rb +0 -1106
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'date'
|
2
|
+
module Barometer
|
3
|
+
#
|
4
|
+
# A simple DateTime class
|
5
|
+
#
|
6
|
+
# A time class that represents the local date_time ...
|
7
|
+
# it has no concept of time zone
|
8
|
+
#
|
9
|
+
class Data::LocalDateTime < Data::LocalTime
|
10
|
+
|
11
|
+
attr_reader :year, :month, :day
|
12
|
+
|
13
|
+
def initialize(y,mon,d,h=0,m=0,s=0)
|
14
|
+
raise(ArgumentError, "invalid date") unless y && mon && d && Date.civil(y,mon,d)
|
15
|
+
@year = y
|
16
|
+
@month = mon
|
17
|
+
@day = d
|
18
|
+
super(h,m,s)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def year=(y)
|
23
|
+
unless y && y.is_a?(Fixnum) && Date.civil(y,@month,@day)
|
24
|
+
raise(ArgumentError, "invalid year")
|
25
|
+
end
|
26
|
+
@year = y
|
27
|
+
end
|
28
|
+
|
29
|
+
def month=(m)
|
30
|
+
unless m && m.is_a?(Fixnum) && Date.civil(@year,m,@day)
|
31
|
+
raise(ArgumentError, "invalid month")
|
32
|
+
end
|
33
|
+
@month = m
|
34
|
+
end
|
35
|
+
|
36
|
+
def day=(d)
|
37
|
+
unless d && d.is_a?(Fixnum) && Date.civil(@year,@month,d)
|
38
|
+
raise(ArgumentError, "invalid day")
|
39
|
+
end
|
40
|
+
@day = d
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse(string)
|
44
|
+
return unless string
|
45
|
+
new_date = Data::LocalDateTime.parse(string)
|
46
|
+
@year = new_date.year
|
47
|
+
@month = new_date.month
|
48
|
+
@day = new_date.day
|
49
|
+
@hour = new_date.hour
|
50
|
+
@min = new_date.min
|
51
|
+
@sec = new_date.sec
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.parse(string)
|
56
|
+
return nil unless string
|
57
|
+
return string if string.is_a?(Data::LocalDateTime)
|
58
|
+
|
59
|
+
year = nil; month = nil; day = nil;
|
60
|
+
hour = nil; min = nil; sec = nil;
|
61
|
+
if string.is_a?(Time) || string.is_a?(DateTime)
|
62
|
+
year = string.year
|
63
|
+
month = string.mon
|
64
|
+
day = string.day
|
65
|
+
hour = string.hour
|
66
|
+
min = string.min
|
67
|
+
sec = string.sec
|
68
|
+
elsif string.is_a?(Date)
|
69
|
+
year = string.year
|
70
|
+
month = string.mon
|
71
|
+
day = string.day
|
72
|
+
elsif string.is_a?(String)
|
73
|
+
datetime = Time.parse(string)
|
74
|
+
year = datetime.year
|
75
|
+
month = datetime.mon
|
76
|
+
day = datetime.day
|
77
|
+
hour = datetime.hour
|
78
|
+
min = datetime.min
|
79
|
+
sec = datetime.sec
|
80
|
+
end
|
81
|
+
Data::LocalDateTime.new(year, month, day, hour, min, sec)
|
82
|
+
end
|
83
|
+
|
84
|
+
# convert to a Date class
|
85
|
+
#
|
86
|
+
def to_d
|
87
|
+
Date.civil(@year, @month, @day)
|
88
|
+
end
|
89
|
+
|
90
|
+
# convert to a DateTime class
|
91
|
+
#
|
92
|
+
def to_dt
|
93
|
+
DateTime.new(@year, @month, @day, @hour, @min, @sec)
|
94
|
+
end
|
95
|
+
|
96
|
+
def <=>(other)
|
97
|
+
if other.is_a?(String) || other.is_a?(Time) || other.is_a?(DateTime) || other.is_a?(Date)
|
98
|
+
the_other = Data::LocalDateTime.parse(other)
|
99
|
+
else
|
100
|
+
the_other = other
|
101
|
+
end
|
102
|
+
raise ArgumentError unless the_other.is_a?(Data::LocalDateTime) || the_other.is_a?(Data::LocalTime)
|
103
|
+
|
104
|
+
if (other.is_a?(String) || other.is_a?(Time) || other.is_a?(DateTime)) &&
|
105
|
+
the_other.is_a?(Data::LocalDateTime)
|
106
|
+
# we are counting days + seconds
|
107
|
+
if (_total_days <=> the_other._total_days) == 0
|
108
|
+
return total_seconds <=> the_other.total_seconds
|
109
|
+
else
|
110
|
+
return _total_days <=> the_other._total_days
|
111
|
+
end
|
112
|
+
elsif other.is_a?(Date) && the_other.is_a?(Data::LocalDateTime)
|
113
|
+
# we are counting days
|
114
|
+
return _total_days <=> the_other._total_days
|
115
|
+
elsif the_other.is_a?(Data::LocalTime)
|
116
|
+
# we are counting seconds
|
117
|
+
return total_seconds <=> the_other.total_seconds
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_s(time=false)
|
122
|
+
datetime = self.to_dt
|
123
|
+
format = (time ? "%Y-%m-%d %I:%M:%S %p" : "%Y-%m-%d")
|
124
|
+
datetime.strftime(format).downcase
|
125
|
+
end
|
126
|
+
|
127
|
+
def nil?; @year == 0 && @month == 0 && @day == 0 && super; end
|
128
|
+
|
129
|
+
# this assumes all years have 366 days (which only is true for leap years)
|
130
|
+
# but since this is just for comparisons, this will be accurate
|
131
|
+
#
|
132
|
+
def _total_days
|
133
|
+
self.to_d.yday + (@year * 366)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module Barometer
|
2
|
+
#
|
3
|
+
# A simple Time class
|
4
|
+
#
|
5
|
+
# A time class that represents the local time ...
|
6
|
+
# it has no concept of time zone or date
|
7
|
+
#
|
8
|
+
class Data::LocalTime
|
9
|
+
include Comparable
|
10
|
+
|
11
|
+
attr_reader :hour, :min, :sec
|
12
|
+
|
13
|
+
def initialize(h=0,m=0,s=0)
|
14
|
+
self.hour = h
|
15
|
+
self.min = m
|
16
|
+
self.sec = s
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def hour=(h)
|
21
|
+
raise ArgumentError unless (h.is_a?(Fixnum) || h.nil?)
|
22
|
+
hour_cap = 24
|
23
|
+
if h.to_i >= hour_cap.to_i
|
24
|
+
@hour = h.divmod(hour_cap)[1]
|
25
|
+
else
|
26
|
+
@hour = h
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def min=(m)
|
31
|
+
raise ArgumentError unless (m.is_a?(Fixnum) || m.nil?)
|
32
|
+
minute_cap = 60
|
33
|
+
if m.to_i >= minute_cap.to_i
|
34
|
+
result = m.divmod(minute_cap)
|
35
|
+
@min = result[1]
|
36
|
+
self.hour = @hour + result[0]
|
37
|
+
else
|
38
|
+
@min = m
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def sec=(s)
|
43
|
+
raise ArgumentError unless (s.is_a?(Fixnum) || s.nil?)
|
44
|
+
second_cap = 60
|
45
|
+
if s.to_i >= second_cap.to_i
|
46
|
+
result = s.divmod(second_cap)
|
47
|
+
@sec = result[1]
|
48
|
+
self.min = @min + result[0]
|
49
|
+
else
|
50
|
+
@sec = s
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse(string)
|
55
|
+
if string.is_a?(Time) || string.is_a?(DateTime)
|
56
|
+
@hour = string.hour
|
57
|
+
@min = string.min
|
58
|
+
@sec = string.sec
|
59
|
+
elsif string.is_a?(String)
|
60
|
+
time = Time.parse(string)
|
61
|
+
@hour = time.hour
|
62
|
+
@min = time.min
|
63
|
+
@sec = time.sec
|
64
|
+
end
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.parse(string)
|
69
|
+
return string if string.is_a?(Data::LocalTime)
|
70
|
+
local = Data::LocalTime.new
|
71
|
+
local.parse(string)
|
72
|
+
local
|
73
|
+
end
|
74
|
+
|
75
|
+
# convert to a Time class
|
76
|
+
#
|
77
|
+
def to_t
|
78
|
+
date = Date.today
|
79
|
+
Time.local(date.year,date.month,date.day,@hour,@min,@sec)
|
80
|
+
end
|
81
|
+
|
82
|
+
def total_seconds
|
83
|
+
(@hour * 60 * 60) + (@min * 60) + @sec
|
84
|
+
end
|
85
|
+
|
86
|
+
def <=>(other)
|
87
|
+
if other.is_a?(String) || other.is_a?(Time) || other.is_a?(DateTime)
|
88
|
+
the_other = Data::LocalTime.parse(other)
|
89
|
+
else
|
90
|
+
the_other = other
|
91
|
+
end
|
92
|
+
raise ArgumentError unless the_other.is_a?(Data::LocalTime)
|
93
|
+
total_seconds <=> the_other.total_seconds
|
94
|
+
end
|
95
|
+
|
96
|
+
def +(seconds)
|
97
|
+
local_time = Data::LocalTime.new
|
98
|
+
if seconds.is_a?(Fixnum) || seconds.is_a?(Float)
|
99
|
+
local_time.sec = self.total_seconds + seconds.to_i
|
100
|
+
elsif seconds.is_a?(Data::LocalTime)
|
101
|
+
this_total = self.total_seconds + seconds.total_seconds
|
102
|
+
local_time.sec = this_total
|
103
|
+
end
|
104
|
+
local_time
|
105
|
+
end
|
106
|
+
|
107
|
+
def -(seconds)
|
108
|
+
local_time = Data::LocalTime.new
|
109
|
+
if seconds.is_a?(Fixnum) || seconds.is_a?(Float)
|
110
|
+
local_time.sec = self.total_seconds - seconds.to_i
|
111
|
+
elsif seconds.is_a?(Data::LocalTime)
|
112
|
+
#self.sec += seconds.total_seconds
|
113
|
+
this_total = self.total_seconds - seconds.total_seconds
|
114
|
+
local_time.sec = this_total
|
115
|
+
end
|
116
|
+
local_time
|
117
|
+
end
|
118
|
+
|
119
|
+
def diff(other)
|
120
|
+
the_other = Data::LocalTime.parse(other)
|
121
|
+
raise ArgumentError unless the_other.is_a?(Data::LocalTime)
|
122
|
+
(self.total_seconds - the_other.total_seconds).to_i.abs
|
123
|
+
end
|
124
|
+
|
125
|
+
def to_s(seconds=false)
|
126
|
+
time = self.to_t
|
127
|
+
format = (seconds ? "%I:%M:%S %p" : "%I:%M %p")
|
128
|
+
time.strftime(format).downcase
|
129
|
+
end
|
130
|
+
|
131
|
+
def nil?; @hour == 0 && @min == 0 && @sec == 0; end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
@@ -6,7 +6,7 @@ module Barometer
|
|
6
6
|
# gave the measurement data for a weather query, or the location
|
7
7
|
# that was queried
|
8
8
|
#
|
9
|
-
class Location
|
9
|
+
class Data::Location
|
10
10
|
|
11
11
|
attr_accessor :id, :name, :city
|
12
12
|
attr_accessor :state_name, :state_code, :country, :country_code, :zip_code
|
@@ -16,5 +16,10 @@ module Barometer
|
|
16
16
|
[@latitude, @longitude].join(',')
|
17
17
|
end
|
18
18
|
|
19
|
+
def to_s
|
20
|
+
[@name, @city, @state_name || @state_cocde,
|
21
|
+
@country || @country_code].compact.join(', ')
|
22
|
+
end
|
23
|
+
|
19
24
|
end
|
20
25
|
end
|
@@ -12,34 +12,35 @@ module Barometer
|
|
12
12
|
# - time_zone information (for the location in question)
|
13
13
|
# - weather station information (for the station that gave collected the data)
|
14
14
|
#
|
15
|
-
class Measurement
|
15
|
+
class Data::Measurement
|
16
16
|
|
17
|
-
|
18
|
-
attr_reader :
|
19
|
-
# current and forecasted data
|
17
|
+
attr_reader :source, :weight
|
18
|
+
attr_reader :measured_at, :utc_time_stamp
|
20
19
|
attr_reader :current, :forecast
|
21
|
-
attr_reader :timezone, :station, :location
|
22
|
-
attr_reader :success
|
23
|
-
attr_accessor :metric
|
20
|
+
attr_reader :timezone, :station, :location, :links
|
21
|
+
attr_reader :success
|
22
|
+
attr_accessor :metric, :query, :format
|
24
23
|
|
25
24
|
def initialize(source=nil, metric=true)
|
26
25
|
@source = source
|
27
26
|
@metric = metric
|
28
27
|
@success = false
|
28
|
+
@weight = 1
|
29
|
+
@links = {}
|
29
30
|
end
|
30
31
|
|
31
32
|
def success!
|
32
|
-
|
33
|
-
|
34
|
-
end
|
33
|
+
current && current.temperature &&
|
34
|
+
!current.temperature.c.nil? && @success = true
|
35
35
|
end
|
36
36
|
|
37
|
-
def stamp!; @
|
37
|
+
def stamp!; @utc_time_stamp = Time.now.utc; end
|
38
38
|
def success?; @success; end
|
39
39
|
def metric?; @metric; end
|
40
40
|
def metric!; @metric=true; end
|
41
41
|
def imperial!; @metric=false; end
|
42
42
|
|
43
|
+
#
|
43
44
|
# this will tell us if the measurement is still current ... if it is still
|
44
45
|
# current this means that the CurrentMeasurement can still used as now
|
45
46
|
#
|
@@ -51,12 +52,17 @@ module Barometer
|
|
51
52
|
# and then you want to know if self.windy?(5_hours_in_future) ... we could
|
52
53
|
# not use the current data for this answser as the time 5_hours_in_future
|
53
54
|
# is not current
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
#
|
56
|
+
def current?(local_time=nil)
|
57
|
+
current_at = ((self.current && self.current.current_at) ?
|
58
|
+
self.current.current_at : self.measured_at)
|
59
|
+
|
60
|
+
local_time = (local_time.nil? ? current_at : Data::LocalTime.parse(local_time))
|
61
|
+
return false unless local_time
|
62
|
+
raise ArgumentError unless local_time.is_a?(Data::LocalTime)
|
63
|
+
|
57
64
|
hours_still_current = 4
|
58
|
-
difference = (
|
59
|
-
difference = (difference*(-1)).to_i if difference < 0
|
65
|
+
difference = (local_time.diff(current_at)).to_i.abs
|
60
66
|
difference <= (60*60*hours_still_current).to_i
|
61
67
|
end
|
62
68
|
|
@@ -73,16 +79,18 @@ module Barometer
|
|
73
79
|
|
74
80
|
# Format date into a Date class
|
75
81
|
date = case date.class.name
|
76
|
-
when 'String'
|
77
|
-
Date.parse(date)
|
78
82
|
when 'Date'
|
79
83
|
date
|
80
|
-
when '
|
81
|
-
|
84
|
+
when 'Data::LocalDateTime'
|
85
|
+
date.to_d
|
86
|
+
when 'String'
|
87
|
+
Date.parse(date)
|
82
88
|
when 'Time'
|
83
89
|
Date.new(date.year, date.month, date.day)
|
90
|
+
when 'DateTime'
|
91
|
+
Date.new(date.year, date.month, date.day)
|
84
92
|
end
|
85
|
-
|
93
|
+
|
86
94
|
day = nil
|
87
95
|
@forecast.each do |f|
|
88
96
|
day = f if date == f.date
|
@@ -90,21 +98,24 @@ module Barometer
|
|
90
98
|
return day
|
91
99
|
end
|
92
100
|
|
101
|
+
#
|
102
|
+
# accesors (with input checking)
|
103
|
+
#
|
104
|
+
|
93
105
|
def source=(source)
|
94
106
|
raise ArgumentError unless source.is_a?(Symbol)
|
95
107
|
@source = source
|
96
108
|
end
|
97
109
|
|
98
|
-
def
|
110
|
+
def utc_time_stamp=(time=Time.now.utc)
|
99
111
|
raise ArgumentError unless time.is_a?(Time)
|
100
|
-
@
|
112
|
+
@utc_time_stamp = time
|
101
113
|
end
|
102
114
|
|
103
115
|
def current=(current)
|
104
|
-
raise ArgumentError unless current.is_a?(
|
116
|
+
raise ArgumentError unless current.is_a?(Data::CurrentMeasurement)
|
105
117
|
@current = current
|
106
118
|
self.stamp!
|
107
|
-
# self-determine success
|
108
119
|
self.success!
|
109
120
|
end
|
110
121
|
|
@@ -114,47 +125,65 @@ module Barometer
|
|
114
125
|
end
|
115
126
|
|
116
127
|
def timezone=(timezone)
|
117
|
-
|
118
|
-
raise ArgumentError unless timezone.is_a?(Barometer::Zone)
|
128
|
+
raise ArgumentError unless timezone.is_a?(Data::Zone)
|
119
129
|
@timezone = timezone
|
120
130
|
end
|
121
131
|
|
122
132
|
def station=(station)
|
123
|
-
raise ArgumentError unless station.is_a?(
|
133
|
+
raise ArgumentError unless station.is_a?(Data::Location)
|
124
134
|
@station = station
|
125
135
|
end
|
126
136
|
|
127
137
|
def location=(location)
|
128
|
-
raise ArgumentError unless location.is_a?(
|
138
|
+
raise ArgumentError unless location.is_a?(Data::Location)
|
129
139
|
@location = location
|
130
140
|
end
|
131
141
|
|
142
|
+
def weight=(weight)
|
143
|
+
raise ArgumentError unless weight.is_a?(Fixnum)
|
144
|
+
@weight = weight
|
145
|
+
end
|
146
|
+
|
147
|
+
def links=(links)
|
148
|
+
raise ArgumentError unless links.is_a?(Hash)
|
149
|
+
@links = links
|
150
|
+
end
|
151
|
+
|
152
|
+
def measured_at=(measured_at)
|
153
|
+
raise ArgumentError unless measured_at.is_a?(Data::LocalTime)
|
154
|
+
@measured_at = measured_at
|
155
|
+
end
|
156
|
+
|
132
157
|
#
|
133
158
|
# simple questions
|
134
159
|
# pass questions to the source
|
135
160
|
#
|
136
161
|
|
137
|
-
def windy?(threshold=10,
|
162
|
+
def windy?(threshold=10, time_string=nil)
|
163
|
+
local_datetime = Data::LocalDateTime.parse(time_string) if time_string
|
138
164
|
raise ArgumentError unless (threshold.is_a?(Fixnum) || threshold.is_a?(Float))
|
139
|
-
raise ArgumentError unless
|
140
|
-
Barometer::
|
165
|
+
raise ArgumentError unless (local_datetime.is_a?(Data::LocalDateTime) || local_datetime.nil?)
|
166
|
+
Barometer::WeatherService.source(@source).windy?(self, threshold, local_datetime)
|
141
167
|
end
|
142
168
|
|
143
|
-
def wet?(threshold=50,
|
169
|
+
def wet?(threshold=50, time_string=nil)
|
170
|
+
local_datetime = Data::LocalDateTime.parse(time_string) if time_string
|
144
171
|
raise ArgumentError unless (threshold.is_a?(Fixnum) || threshold.is_a?(Float))
|
145
|
-
raise ArgumentError unless
|
146
|
-
Barometer::
|
172
|
+
raise ArgumentError unless (local_datetime.is_a?(Data::LocalDateTime) || local_datetime.nil?)
|
173
|
+
Barometer::WeatherService.source(@source).wet?(self, threshold, local_datetime)
|
147
174
|
end
|
148
175
|
|
149
|
-
def day?(
|
150
|
-
|
151
|
-
|
176
|
+
def day?(time_string=nil)
|
177
|
+
local_datetime = Data::LocalDateTime.parse(time_string) if time_string
|
178
|
+
raise ArgumentError unless (local_datetime.is_a?(Data::LocalDateTime) || local_datetime.nil?)
|
179
|
+
Barometer::WeatherService.source(@source).day?(self, local_datetime)
|
152
180
|
end
|
153
181
|
|
154
|
-
def sunny?(
|
155
|
-
|
156
|
-
|
157
|
-
|
182
|
+
def sunny?(time_string=nil)
|
183
|
+
local_datetime = Data::LocalDateTime.parse(time_string) if time_string
|
184
|
+
raise ArgumentError unless (local_datetime.is_a?(Data::LocalDateTime) || local_datetime.nil?)
|
185
|
+
return false if self.day?(local_datetime) == false
|
186
|
+
Barometer::WeatherService.source(@source).sunny?(self, local_datetime)
|
158
187
|
end
|
159
188
|
|
160
189
|
end
|