barometer 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +78 -70
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +100 -37
  4. data/lib/barometer.rb +12 -8
  5. data/lib/barometer/base.rb +48 -20
  6. data/lib/barometer/data.rb +5 -1
  7. data/lib/barometer/data/current.rb +23 -15
  8. data/lib/barometer/data/distance.rb +15 -5
  9. data/lib/barometer/data/forecast.rb +23 -5
  10. data/lib/barometer/data/geo.rb +16 -54
  11. data/lib/barometer/data/local_datetime.rb +137 -0
  12. data/lib/barometer/data/local_time.rb +134 -0
  13. data/lib/barometer/data/location.rb +6 -1
  14. data/lib/barometer/data/measurement.rb +71 -42
  15. data/lib/barometer/data/night.rb +69 -0
  16. data/lib/barometer/data/pressure.rb +15 -5
  17. data/lib/barometer/data/speed.rb +16 -5
  18. data/lib/barometer/data/sun.rb +8 -20
  19. data/lib/barometer/data/temperature.rb +22 -9
  20. data/lib/barometer/data/units.rb +10 -19
  21. data/lib/barometer/data/zone.rb +135 -9
  22. data/lib/barometer/formats.rb +12 -0
  23. data/lib/barometer/formats/coordinates.rb +42 -0
  24. data/lib/barometer/formats/format.rb +46 -0
  25. data/lib/barometer/formats/geocode.rb +51 -0
  26. data/lib/barometer/formats/icao.rb +37 -0
  27. data/lib/barometer/formats/postalcode.rb +22 -0
  28. data/lib/barometer/formats/short_zipcode.rb +17 -0
  29. data/lib/barometer/formats/weather_id.rb +107 -0
  30. data/lib/barometer/formats/zipcode.rb +31 -0
  31. data/lib/barometer/query.rb +61 -232
  32. data/lib/barometer/services.rb +14 -4
  33. data/lib/barometer/translations/icao_country_codes.yml +9 -0
  34. data/lib/barometer/translations/weather_country_codes.yml +17 -0
  35. data/lib/barometer/weather.rb +51 -30
  36. data/lib/barometer/{services → weather_services}/google.rb +23 -26
  37. data/lib/barometer/weather_services/noaa.rb +6 -0
  38. data/lib/barometer/{services → weather_services}/service.rb +101 -92
  39. data/lib/barometer/weather_services/weather_bug.rb +6 -0
  40. data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
  41. data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
  42. data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
  43. data/lib/barometer/web_services/geocode.rb +33 -0
  44. data/lib/barometer/web_services/weather_id.rb +37 -0
  45. data/lib/barometer/web_services/web_service.rb +32 -0
  46. data/lib/demometer/demometer.rb +31 -4
  47. data/lib/demometer/views/forecast.erb +20 -0
  48. data/lib/demometer/views/index.erb +10 -3
  49. data/lib/demometer/views/measurement.erb +8 -3
  50. data/lib/demometer/views/readme.erb +63 -24
  51. data/spec/barometer_spec.rb +18 -36
  52. data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
  53. data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
  54. data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
  55. data/spec/data/geo_spec.rb +91 -0
  56. data/spec/data/local_datetime_spec.rb +269 -0
  57. data/spec/data/local_time_spec.rb +239 -0
  58. data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
  59. data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
  60. data/spec/data/night_measurement_spec.rb +136 -0
  61. data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
  62. data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
  63. data/spec/data/sun_spec.rb +49 -0
  64. data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
  65. data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
  66. data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
  67. data/spec/fixtures/formats/weather_id/90210.xml +1 -0
  68. data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
  69. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
  70. data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
  71. data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
  72. data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
  73. data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
  74. data/spec/fixtures/geocode/atlanta.xml +1 -0
  75. data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
  76. data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
  77. data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
  78. data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
  79. data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
  80. data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
  81. data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
  82. data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
  83. data/spec/formats/coordinates_spec.rb +158 -0
  84. data/spec/formats/format_spec.rb +73 -0
  85. data/spec/formats/geocode_spec.rb +179 -0
  86. data/spec/formats/icao_spec.rb +61 -0
  87. data/spec/formats/postalcode_spec.rb +59 -0
  88. data/spec/formats/short_zipcode_spec.rb +53 -0
  89. data/spec/formats/weather_id_spec.rb +191 -0
  90. data/spec/formats/zipcode_spec.rb +111 -0
  91. data/spec/query_spec.rb +261 -288
  92. data/spec/spec_helper.rb +128 -4
  93. data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
  94. data/spec/weather_services/services_spec.rb +1118 -0
  95. data/spec/weather_services/weather_dot_com_spec.rb +327 -0
  96. data/spec/weather_services/wunderground_spec.rb +332 -0
  97. data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
  98. data/spec/weather_spec.rb +73 -61
  99. data/spec/web_services/geocode_spec.rb +45 -0
  100. data/spec/web_services/web_services_spec.rb +26 -0
  101. metadata +88 -36
  102. data/lib/barometer/services/noaa.rb +0 -6
  103. data/lib/barometer/services/weather_bug.rb +0 -6
  104. data/lib/barometer/services/weather_dot_com.rb +0 -6
  105. data/spec/data_geo_spec.rb +0 -94
  106. data/spec/data_sun_spec.rb +0 -76
  107. data/spec/service_wunderground_spec.rb +0 -330
  108. data/spec/services_spec.rb +0 -1106
@@ -0,0 +1,69 @@
1
+ require 'date'
2
+ module Barometer
3
+ #
4
+ # Night Measurement
5
+ # a data class for forecasted night weather conditions
6
+ #
7
+ # This is basically a data holding class for the forecasted night
8
+ # weather conditions.
9
+ #
10
+ class Data::NightMeasurement
11
+
12
+ attr_reader :date, :icon, :condition
13
+ attr_reader :pop, :wind, :humidity
14
+
15
+ # accessors (with input checking)
16
+ #
17
+ def date=(date)
18
+ raise ArgumentError unless date.is_a?(Date)
19
+ @date = date
20
+ end
21
+
22
+ def icon=(icon)
23
+ raise ArgumentError unless icon.is_a?(String)
24
+ @icon = icon
25
+ end
26
+
27
+ def condition=(condition)
28
+ raise ArgumentError unless condition.is_a?(String)
29
+ @condition = condition
30
+ end
31
+
32
+ def pop=(pop)
33
+ raise ArgumentError unless pop.is_a?(Fixnum)
34
+ @pop = pop
35
+ end
36
+
37
+ def wind=(wind)
38
+ raise ArgumentError unless wind.is_a?(Data::Speed)
39
+ @wind = wind
40
+ end
41
+
42
+ def humidity=(humidity)
43
+ raise ArgumentError unless humidity.is_a?(Fixnum)
44
+ @humidity = humidity
45
+ end
46
+
47
+ def sun=(sun)
48
+ raise ArgumentError unless sun.is_a?(Data::Sun)
49
+ @sun = sun
50
+ end
51
+
52
+ #
53
+ # helpers
54
+ #
55
+
56
+ # creates "?" helpers for all attributes (which maps to nil?)
57
+ #
58
+ def method_missing(method,*args)
59
+ # if the method ends in ?, then strip it off and see if we
60
+ # respond to the method without the ?
61
+ if (call_method = method.to_s.chomp!("?")) && respond_to?(call_method)
62
+ return send(call_method).nil? ? false : true
63
+ else
64
+ super(method,*args)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -12,7 +12,7 @@ module Barometer
12
12
  # that this class was designed for storing weather data,
13
13
  # and it seems that it is more common in this case
14
14
  #
15
- class Pressure < Barometer::Units
15
+ class Data::Pressure < Data::Units
16
16
 
17
17
  METRIC_UNITS = "mb"
18
18
  IMPERIAL_UNITS = "in"
@@ -48,6 +48,7 @@ module Barometer
48
48
  #
49
49
 
50
50
  # store millibars
51
+ #
51
52
  def mb=(mb)
52
53
  return if !mb || !(mb.is_a?(Integer) || mb.is_a?(Float))
53
54
  @millibars = mb.to_f
@@ -55,6 +56,7 @@ module Barometer
55
56
  end
56
57
 
57
58
  # store inches
59
+ #
58
60
  def in=(inches)
59
61
  return if !inches || !(inches.is_a?(Integer) || inches.is_a?(Float))
60
62
  @inches = inches.to_f
@@ -62,14 +64,16 @@ module Barometer
62
64
  end
63
65
 
64
66
  # return the stored millibars or convert from inches
67
+ #
65
68
  def mb(as_integer=true)
66
- mb = (@millibars || Pressure.in_to_mb(@inches))
69
+ mb = (@millibars || Data::Pressure.in_to_mb(@inches))
67
70
  mb ? (as_integer ? mb.to_i : (100*mb).round/100.0) : nil
68
71
  end
69
72
 
70
73
  # return the stored inches or convert from millibars
74
+ #
71
75
  def in(as_integer=true)
72
- inches = (@inches || Pressure.mb_to_in(@millibars))
76
+ inches = (@inches || Data::Pressure.mb_to_in(@millibars))
73
77
  inches ? (as_integer ? inches.to_i : (100*inches).round/100.0) : nil
74
78
  end
75
79
 
@@ -86,30 +90,35 @@ module Barometer
86
90
  #
87
91
 
88
92
  # will just return the value (no units)
93
+ #
89
94
  def to_i(metric=nil)
90
95
  (metric || (metric.nil? && self.metric?)) ? self.mb : self.in
91
96
  end
92
97
 
93
98
  # will just return the value (no units) with more precision
99
+ #
94
100
  def to_f(metric=nil)
95
101
  (metric || (metric.nil? && self.metric?)) ? self.mb(false) : self.in(false)
96
102
  end
97
103
 
98
104
  # will return the value with units
105
+ #
99
106
  def to_s(metric=nil)
100
107
  (metric || (metric.nil? && self.metric?)) ? "#{self.mb} #{METRIC_UNITS}" : "#{self.in} #{IMPERIAL_UNITS}"
101
108
  end
102
109
 
103
110
  # will just return the units (no value)
111
+ #
104
112
  def units(metric=nil)
105
113
  (metric || (metric.nil? && self.metric?)) ? METRIC_UNITS : IMPERIAL_UNITS
106
114
  end
107
115
 
108
116
  # when we set inches, it is possible the a non-equivalent value of
109
117
  # millibars remains. if so, clear it.
118
+ #
110
119
  def update_millibars(inches)
111
120
  return unless @millibars
112
- difference = Pressure.in_to_mb(inches.to_f) - @millibars
121
+ difference = Data::Pressure.in_to_mb(inches.to_f) - @millibars
113
122
  # only clear millibars if the stored millibars is off be more then 1 unit
114
123
  # then the conversion of inches
115
124
  @millibars = nil unless difference.abs <= 1.0
@@ -117,9 +126,10 @@ module Barometer
117
126
 
118
127
  # when we set millibars, it is possible the a non-equivalent value of
119
128
  # inches remains. if so, clear it.
129
+ #
120
130
  def update_inches(mb)
121
131
  return unless @inches
122
- difference = Pressure.mb_to_in(mb.to_f) - @inches
132
+ difference = Data::Pressure.mb_to_in(mb.to_f) - @inches
123
133
  # only clear inches if the stored inches is off be more then 1 unit
124
134
  # then the conversion of millibars
125
135
  @inches = nil unless difference.abs <= 1.0
@@ -14,7 +14,8 @@ module Barometer
14
14
  # NOTE: this currently only supports the scale of
15
15
  # kilometers (km) and miles (m) per hour. There is currently
16
16
  # no way to scale to smaller units (eg km -> m -> mm)
17
- class Speed < Barometer::Units
17
+ #
18
+ class Data::Speed < Data::Units
18
19
 
19
20
  METRIC_UNITS = "kph"
20
21
  IMPERIAL_UNITS = "mph"
@@ -52,6 +53,7 @@ module Barometer
52
53
  #
53
54
 
54
55
  # store kilometers per hour
56
+ #
55
57
  def kph=(kph)
56
58
  return if !kph || !(kph.is_a?(Integer) || kph.is_a?(Float))
57
59
  @kilometers = kph.to_f
@@ -59,6 +61,7 @@ module Barometer
59
61
  end
60
62
 
61
63
  # store miles per hour
64
+ #
62
65
  def mph=(mph)
63
66
  return if !mph || !(mph.is_a?(Integer) || mph.is_a?(Float))
64
67
  @miles = mph.to_f
@@ -76,14 +79,16 @@ module Barometer
76
79
  end
77
80
 
78
81
  # return the stored kilometers or convert from miles
82
+ #
79
83
  def kph(as_integer=true)
80
- km = (@kilometers || Speed.m_to_km(@miles))
84
+ km = (@kilometers || Data::Speed.m_to_km(@miles))
81
85
  km ? (as_integer ? km.to_i : (100*km).round/100.0) : nil
82
86
  end
83
87
 
84
88
  # return the stored miles or convert from kilometers
89
+ #
85
90
  def mph(as_integer=true)
86
- m = (@miles || Speed.km_to_m(@kilometers))
91
+ m = (@miles || Data::Speed.km_to_m(@kilometers))
87
92
  m ? (as_integer ? m.to_i : (100*m).round/100.0) : nil
88
93
  end
89
94
 
@@ -100,30 +105,35 @@ module Barometer
100
105
  #
101
106
 
102
107
  # will just return the value (no units)
108
+ #
103
109
  def to_i(metric=nil)
104
110
  (metric || (metric.nil? && self.metric?)) ? self.kph : self.mph
105
111
  end
106
112
 
107
113
  # will just return the value (no units) with more precision
114
+ #
108
115
  def to_f(metric=nil)
109
116
  (metric || (metric.nil? && self.metric?)) ? self.kph(false) : self.mph(false)
110
117
  end
111
118
 
112
119
  # will return the value with units
120
+ #
113
121
  def to_s(metric=nil)
114
122
  (metric || (metric.nil? && self.metric?)) ? "#{self.kph} #{METRIC_UNITS}" : "#{self.mph} #{IMPERIAL_UNITS}"
115
123
  end
116
124
 
117
125
  # will just return the units (no value)
126
+ #
118
127
  def units(metric=nil)
119
128
  (metric || (metric.nil? && self.metric?)) ? METRIC_UNITS : IMPERIAL_UNITS
120
129
  end
121
130
 
122
131
  # when we set miles, it is possible the a non-equivalent value of
123
132
  # kilometers remains. if so, clear it.
133
+ #
124
134
  def update_kilometers(m)
125
135
  return unless @kilometers
126
- difference = Speed.m_to_km(m.to_f) - @kilometers
136
+ difference = Data::Speed.m_to_km(m.to_f) - @kilometers
127
137
  # only clear kilometers if the stored kilometers is off be more then 1 unit
128
138
  # then the conversion of miles
129
139
  @kilometers = nil unless difference.abs <= 1.0
@@ -131,9 +141,10 @@ module Barometer
131
141
 
132
142
  # when we set kilometers, it is possible the a non-equivalent value of
133
143
  # miles remains. if so, clear it.
144
+ #
134
145
  def update_miles(km)
135
146
  return unless @miles
136
- difference = Speed.km_to_m(km.to_f) - @miles
147
+ difference = Data::Speed.km_to_m(km.to_f) - @miles
137
148
  # only clear miles if the stored miles is off be more then 1 unit
138
149
  # then the conversion of kilometers
139
150
  @miles = nil unless difference.abs <= 1.0
@@ -4,31 +4,19 @@ module Barometer
4
4
  #
5
5
  # Used to store sunrise and sunset information
6
6
  #
7
- class Sun
7
+ class Data::Sun
8
+
9
+ attr_reader :rise, :set
8
10
 
9
11
  def initialize(rise=nil, set=nil)
10
- raise ArgumentError unless (rise.is_a?(Time) || rise.nil?)
11
- raise ArgumentError unless (set.is_a?(Time) || set.nil?)
12
- @rise_utc = rise
13
- @set_utc = set
12
+ raise ArgumentError unless (rise.is_a?(Data::LocalTime) || rise.nil?)
13
+ raise ArgumentError unless (set.is_a?(Data::LocalTime) || set.nil?)
14
+ @rise = rise
15
+ @set = set
14
16
  end
15
17
 
16
- def rise; @rise_utc; end
17
- def set; @set_utc; end
18
-
19
- # useful for incrementing the sunrise and sunset times by exactly
20
- # N days ... used when using the same sun data for other days
21
- def self.add_days!(sun, n=1)
22
- raise ArgumentError unless sun.is_a?(Barometer::Sun)
23
- raise ArgumentError unless n.is_a?(Fixnum)
24
- seconds_to_add = 60*60*24*n
25
- rise_utc = sun.rise + seconds_to_add
26
- set_utc = sun.set + seconds_to_add
27
- self.new(rise_utc, set_utc)
28
- end
29
-
30
18
  def nil?
31
- (@rise_utc || @set_utc) ? false : true
19
+ (@rise || @set) ? false : true
32
20
  end
33
21
 
34
22
  end
@@ -9,7 +9,7 @@ module Barometer
9
9
  # All comparison operations will be done in the absolute
10
10
  # scale of Kelvin (K)
11
11
  #
12
- class Temperature < Barometer::Units
12
+ class Data::Temperature < Data::Units
13
13
 
14
14
  METRIC_UNITS = "C"
15
15
  IMPERIAL_UNITS = "F"
@@ -36,12 +36,14 @@ module Barometer
36
36
  end
37
37
 
38
38
  # Tf = (9/5)*Tc+32
39
+ #
39
40
  def self.c_to_f(c)
40
41
  return nil unless c && (c.is_a?(Integer) || c.is_a?(Float))
41
42
  ((9.0/5.0)*c.to_f)+32.0
42
43
  end
43
44
 
44
45
  # Tc = (5/9)*(Tf-32)
46
+ #
45
47
  def self.f_to_c(f)
46
48
  return nil unless f && (f.is_a?(Integer) || f.is_a?(Float))
47
49
  (5.0/9.0)*(f.to_f-32.0)
@@ -69,38 +71,43 @@ module Barometer
69
71
  #
70
72
 
71
73
  # store celsius and kelvin
74
+ #
72
75
  def c=(c)
73
76
  return if !c || !(c.is_a?(Integer) || c.is_a?(Float))
74
77
  @celsius = c.to_f
75
- @kelvin = Temperature.c_to_k(c.to_f)
78
+ @kelvin = Data::Temperature.c_to_k(c.to_f)
76
79
  self.update_fahrenheit(c.to_f)
77
80
  end
78
81
 
79
82
  # store fahrenheit and kelvin
83
+ #
80
84
  def f=(f)
81
85
  return if !f || !(f.is_a?(Integer) || f.is_a?(Float))
82
86
  @fahrenheit = f.to_f
83
- @kelvin = Temperature.f_to_k(f.to_f)
87
+ @kelvin = Data::Temperature.f_to_k(f.to_f)
84
88
  self.update_celsius(f.to_f)
85
89
  end
86
90
 
87
91
  # store kelvin, convert to all
92
+ #
88
93
  def k=(k)
89
94
  return if !k || !(k.is_a?(Integer) || k.is_a?(Float))
90
95
  @kelvin = k.to_f
91
- @celsius = Temperature.k_to_c(k.to_f)
92
- @fahrenheit = Temperature.k_to_f(k.to_f)
96
+ @celsius = Data::Temperature.k_to_c(k.to_f)
97
+ @fahrenheit = Data::Temperature.k_to_f(k.to_f)
93
98
  end
94
99
 
95
100
  # return the stored celsius or convert from Kelvin
101
+ #
96
102
  def c(as_integer=true)
97
- c = (@celsius || Temperature.k_to_c(@kelvin))
103
+ c = (@celsius || Data::Temperature.k_to_c(@kelvin))
98
104
  c ? (as_integer ? c.to_i : (100*c).round/100.0) : nil
99
105
  end
100
106
 
101
107
  # return the stored fahrenheit or convert from Kelvin
108
+ #
102
109
  def f(as_integer=true)
103
- f = (@fahrenheit || Temperature.k_to_f(@kelvin))
110
+ f = (@fahrenheit || Data::Temperature.k_to_f(@kelvin))
104
111
  f ? (as_integer ? f.to_i : (100*f).round/100.0) : nil
105
112
  end
106
113
 
@@ -117,30 +124,35 @@ module Barometer
117
124
  #
118
125
 
119
126
  # will just return the value (no units)
127
+ #
120
128
  def to_i(metric=nil)
121
129
  (metric || (metric.nil? && self.metric?)) ? self.c : self.f
122
130
  end
123
131
 
124
132
  # will just return the value (no units) with more precision
133
+ #
125
134
  def to_f(metric=nil)
126
135
  (metric || (metric.nil? && self.metric?)) ? self.c(false) : self.f(false)
127
136
  end
128
137
 
129
138
  # will return the value with units
139
+ #
130
140
  def to_s(metric=nil)
131
141
  (metric || (metric.nil? && self.metric?)) ? "#{self.c} #{METRIC_UNITS}" : "#{self.f} #{IMPERIAL_UNITS}"
132
142
  end
133
143
 
134
144
  # will just return the units (no value)
145
+ #
135
146
  def units(metric=nil)
136
147
  (metric || (metric.nil? && self.metric?)) ? METRIC_UNITS : IMPERIAL_UNITS
137
148
  end
138
149
 
139
150
  # when we set fahrenheit, it is possible the a non-equivalent value of
140
151
  # celsius remains. if so, clear it.
152
+ #
141
153
  def update_celsius(f)
142
154
  return unless @celsius
143
- difference = Temperature.f_to_c(f.to_f) - @celsius
155
+ difference = Data::Temperature.f_to_c(f.to_f) - @celsius
144
156
  # only clear celsius if the stored celsius is off be more then 1 degree
145
157
  # then the conversion of fahrenheit
146
158
  @celsius = nil unless difference.abs <= 1.0
@@ -148,9 +160,10 @@ module Barometer
148
160
 
149
161
  # when we set celsius, it is possible the a non-equivalent value of
150
162
  # fahrenheit remains. if so, clear it.
163
+ #
151
164
  def update_fahrenheit(c)
152
165
  return unless @fahrenheit
153
- difference = Temperature.c_to_f(c.to_f) - @fahrenheit
166
+ difference = Data::Temperature.c_to_f(c.to_f) - @fahrenheit
154
167
  # only clear fahrenheit if the stored fahrenheit is off be more then 1 degree
155
168
  # then the conversion of celsius
156
169
  @fahrenheit = nil unless difference.abs <= 1.0
@@ -1,12 +1,10 @@
1
1
  module Barometer
2
- class Units
2
+ class Data::Units
3
3
  include Comparable
4
4
 
5
5
  attr_accessor :metric
6
6
 
7
- def initialize(metric=true)
8
- @metric = metric
9
- end
7
+ def initialize(metric=true); @metric = metric; end
10
8
 
11
9
  #
12
10
  # HELPERS
@@ -16,12 +14,13 @@ module Barometer
16
14
  def metric!; @metric=true; end
17
15
  def imperial!; @metric=false; end
18
16
 
19
- # assigns a value to the right attribute based on metric setting
17
+ # assigns a value to the right attribute based on metric setting
18
+ #
20
19
  def <<(value)
21
20
  return unless value
22
21
 
23
22
  # these values can be treated like 'nil'
24
- nil_values = ["NA"]
23
+ nil_values = ["NA", "N/A", ""]
25
24
 
26
25
  begin
27
26
  if value.is_a?(Array)
@@ -37,22 +36,14 @@ module Barometer
37
36
  # do nothing
38
37
  end
39
38
 
40
- if self.metric?
41
- self.metric_default = value_m || value_b
42
- else
39
+ self.metric? ? self.metric_default = value_m || value_b :
43
40
  self.imperial_default = value_i || value_b
44
- end
45
41
  end
46
42
 
47
- # STUB: define this method to actually retireve the metric_default
48
- def metric_default=(value)
49
- raise NotImplementedError
50
- end
51
-
52
- # STUB: define this method to actually retireve the imperial_default
53
- def imperial_default=(value)
54
- raise NotImplementedError
55
- end
43
+ # stubs
44
+ #
45
+ def metric_default=(value); raise NotImplementedError; end
46
+ def imperial_default=(value); raise NotImplementedError; end
56
47
 
57
48
  end
58
49
  end