Class: MeteofranceApi::Rain

Inherits:
Object
  • Object
show all
Defined in:
lib/meteofrance_api/models/rain.rb

Defined Under Namespace

Classes: Forecast

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Rain

Returns a new instance of Rain.



15
16
17
18
19
20
21
22
23
24
# File 'lib/meteofrance_api/models/rain.rb', line 15

def initialize(data)
  @updated_on = Time.at(data["updated_time"]).utc
  @position = data["geometry"]["coordinates"]
  @place_name = data["properties"]["name"]
  @altitude = data["properties"]["altitude"]
  @french_department = data["properties"]["french_department"]
  @timezone = data["properties"]["timezone"]
  @forecasts = data["properties"]["forecast"].map {|d| MeteofranceApi::Rain::Forecast.new(d)}
  @confidence = data["properties"]["confidence"]
end

Instance Attribute Details

#altitudeObject (readonly)

Returns the value of attribute altitude.



7
8
9
# File 'lib/meteofrance_api/models/rain.rb', line 7

def altitude
  @altitude
end

#confidenceObject (readonly)

quality of the rain forecast.



13
14
15
# File 'lib/meteofrance_api/models/rain.rb', line 13

def confidence
  @confidence
end

#forecastsObject (readonly)

the rain forecast.



11
12
13
# File 'lib/meteofrance_api/models/rain.rb', line 11

def forecasts
  @forecasts
end

#french_departmentObject (readonly)

Returns the value of attribute french_department.



8
9
10
# File 'lib/meteofrance_api/models/rain.rb', line 8

def french_department
  @french_department
end

#place_nameObject (readonly)

position information of the rain forecast ([latitude, longitude]).



5
6
7
# File 'lib/meteofrance_api/models/rain.rb', line 5

def place_name
  @place_name
end

#positionObject (readonly)

Returns the value of attribute position.



6
7
8
# File 'lib/meteofrance_api/models/rain.rb', line 6

def position
  @position
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



9
10
11
# File 'lib/meteofrance_api/models/rain.rb', line 9

def timezone
  @timezone
end

#updated_onObject (readonly)

update time of the rain forecast.



3
4
5
# File 'lib/meteofrance_api/models/rain.rb', line 3

def updated_on
  @updated_on
end

Instance Method Details

#next_rain_date(use_position_timezone) ⇒ Object

Estimate the date of the next rain.

Returns:

A datetime instance representing the date estimation of the next rain within
the next hour.
If no rain is expected in the following hour nil is returned.


36
37
38
39
40
41
# File 'lib/meteofrance_api/models/rain.rb', line 36

def next_rain_date(use_position_timezone)
  # search first cadran with rain
  next_rain = forecasts.find {|f| f.intensity > 1}

  next_rain&.time
end

#to_locale_timezone(time) ⇒ Object



26
27
28
# File 'lib/meteofrance_api/models/rain.rb', line 26

def to_locale_timezone(time)
  time.in_time_zone(position["timezone"])
end