Class: Barometer::Measurement::ForecastArray

Inherits:
Array
  • Object
show all
Defined in:
lib/barometer/measurements/forecast_array.rb

Overview

Forecast Array an array that holds multiple forecasts

Instance Method Summary collapse

Instance Method Details

#<<(forecast) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/barometer/measurements/forecast_array.rb', line 9

def <<(forecast)
  raise ArgumentError unless forecast.is_a?(Measurement::Forecast)
  super(forecast)
end

#[](index) ⇒ Object



14
15
16
# File 'lib/barometer/measurements/forecast_array.rb', line 14

def [](index)
  index.is_a?(Fixnum) ? super(index) : self.for(index)
end

#day?(datetime) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/barometer/measurements/forecast_array.rb', line 57

def day?(datetime)
  local_time = Data::LocalTime.parse(datetime)
  (forecast = self[datetime]) ? forecast.day?(local_time) : nil
end

#for(date) ⇒ Object

Returns a forecast for a day given by a Date, DateTime, Time, or a string that can be parsed to a date

credit: github.com/jdpace/weatherman/



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/barometer/measurements/forecast_array.rb', line 24

def for(date)

  return nil unless self.size > 0
  
  # Format date into a Date class
  date = case date.class.name
  when 'Date'
    date
  when 'Data::LocalDateTime'
    date.to_d
  when 'String'
    Date.parse(date)
  when 'Time'
    Date.new(date.year, date.month, date.day)
  when 'DateTime'
    Date.new(date.year, date.month, date.day)
  end
  
  day = nil
  self.each do |f|
    day = f if date == f.date
  end
  return day
end

#sunny?(datetime, sunny_icons = nil) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/barometer/measurements/forecast_array.rb', line 62

def sunny?(datetime, sunny_icons=nil)
  local_time = Data::LocalTime.parse(datetime)
  (forecast = self[datetime]) ? forecast.sunny?(local_time, sunny_icons) : nil
end

#wet?(datetime, wet_icons = nil, pop_threshold = 50, humidity_threshold = 99) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/barometer/measurements/forecast_array.rb', line 67

def wet?(datetime, wet_icons=nil, pop_threshold=50, humidity_threshold=99)
  (forecast = self[datetime]) ? forecast.wet?(wet_icons,pop_threshold,humidity_threshold) : nil
end

#windy?(datetime, threshold = 10) ⇒ Boolean

answer simple questions

Returns:

  • (Boolean)


53
54
55
# File 'lib/barometer/measurements/forecast_array.rb', line 53

def windy?(datetime, threshold=10)
  (forecast = self[datetime]) ? forecast.windy?(threshold) : nil
end