Class: Barometer::Measurement::ResultArray

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

Overview

Result Array

an array that holds multiple results, with methods for insertion and searching

Instance Method Summary collapse

Instance Method Details

#<<(forecast) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/barometer/measurements/result_array.rb', line 11

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

#[](index) ⇒ Object



16
17
18
# File 'lib/barometer/measurements/result_array.rb', line 16

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

#day?(datetime) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/barometer/measurements/result_array.rb', line 60

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

#for(datetime) ⇒ Object

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

credit: github.com/jdpace/weatherman/



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

def for(datetime)

  return nil unless self.size > 0
  
  # Format date into a Date class
  datetime = case datetime.class.name
  when 'Date'
    # if just given a date, assume a time that will be mid-day
    Data::LocalDateTime.new(datetime.year,datetime.month,datetime.day,12,0,0)
  when 'Data::LocalDateTime'
    datetime
  when 'String'
    Data::LocalDateTime.parse(datetime)
  when 'Time'
    Data::LocalDateTime.parse(datetime)
  when 'DateTime'
    Data::LocalDateTime.parse(datetime)
  end
  
  day = nil
  self.each do |f|
    day = f if f.for_datetime?(datetime)
  end
  return day
end

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

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/barometer/measurements/result_array.rb', line 65

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)


70
71
72
# File 'lib/barometer/measurements/result_array.rb', line 70

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)


56
57
58
# File 'lib/barometer/measurements/result_array.rb', line 56

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