Class: S44_MyWeatherForecast

Inherits:
Object
  • Object
show all
Defined in:
lib/s44_myweatherforecast.rb

Instance Method Summary collapse

Constructor Details

#initialize(myweatherforecast = nil) ⇒ S44_MyWeatherForecast

Returns a new instance of S44_MyWeatherForecast.



8
9
10
# File 'lib/s44_myweatherforecast.rb', line 8

def initialize(myweatherforecast=nil)
  @w = myweatherforecast
end

Instance Method Details

#afternoonObject Also known as: this_afternoon



12
13
14
# File 'lib/s44_myweatherforecast.rb', line 12

def afternoon()
  summary :afternoon
end

#ahead(advance = 2) ⇒ Object



16
17
18
# File 'lib/s44_myweatherforecast.rb', line 16

def ahead(advance=2)
  self.method(@w.today.ahead(advance)).call
end

#early_hoursObject



22
23
24
# File 'lib/s44_myweatherforecast.rb', line 22

def early_hours()
  summary :early_hours
end

#eveningObject Also known as: this_evening



30
31
32
# File 'lib/s44_myweatherforecast.rb', line 30

def evening()
  summary :evening
end

#morningObject



26
27
28
# File 'lib/s44_myweatherforecast.rb', line 26

def morning
  summary :morning
end

#query(day = :tomorrow, desc = 'rain', time: false, times: false) ⇒ Object

e.g. is it going to rain tomorrow? return an array of periods within the day of when it will rain or an empty array if there is no rain forecast



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/s44_myweatherforecast.rb', line 37

def query(day=:tomorrow, desc='rain', time: false, times: false)

  r2 = %i(morning afternoon evening early_hours night).map do |x| 
    
    r = if times then
      query_period(day.to_sym, x, desc, single_result: false)
    else
      query_period(day.to_sym, x, desc)
    end
  
    next unless r
    
    if time then
      
      [x, [r.time, r.summary]]
      
    elsif times
      
      next if r.empty?
      [x, r.map {|y| [y.time, y.summary]}]
      
    else
      x
    end
  end
  
  r2.compact
  
end

#query_period(day = :tomorrow, period = :afternoon, desc = 'rain', single_result: true) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/s44_myweatherforecast.rb', line 67

def query_period(day=:tomorrow, period=:afternoon, desc='rain', 
                 single_result: true)

  desc = 'drizzle|rain|snow|sleet' if desc =~ /rain/i
  obj_period = @w.method(day.to_sym).call.method(period.to_sym).call

  return if obj_period.nil?
  
  name = single_result ? :detect : :select
  
  obj_period.method(name).call {|x| x.to_s =~ /#{desc}/i }
  
end

#tomorrowObject



83
84
85
86
87
88
89
# File 'lib/s44_myweatherforecast.rb', line 83

def tomorrow()
  
  s = @w.tomorrow.to_s
  min, max, desc = s.match(/\w+:\s+([^ ]+) ([^,]+),\s+(.*)\.$/).captures    
  outlook('tomorrow', min, max, desc: desc)
  
end

#tonightObject Also known as: night



91
92
93
# File 'lib/s44_myweatherforecast.rb', line 91

def tonight()
  summary :night
end