Class: WrfForecast::Text::SuntimeText
- Inherits:
-
Object
- Object
- WrfForecast::Text::SuntimeText
- Defined in:
- lib/wrf_forecast/forecast/suntime_text.rb
Overview
This class determines the time for sunrise and the sunset for a given location and a given day. The time is formatted in a human readable time. With that this class generates the text passage of the text forecast presenting these times
Instance Attribute Summary collapse
-
#text ⇒ String
readonly
The part of the forcast text containing sunrise and sunset.
Instance Method Summary collapse
-
#format_time(time) ⇒ String
private
helper method to format the time from a Float to a timestamp with hh:mm.
-
#generate_sunrise_text(date, coordinate) ⇒ String
private
method to calculate the sunrise time and the text part for the sunrise.
-
#generate_sunset_text(date, coordinate) ⇒ String
private
method to calculate the sunset time and the text part for the sunset.
-
#initialize(meta_data) ⇒ SuntimeText
constructor
initialization.
Constructor Details
#initialize(meta_data) ⇒ SuntimeText
initialization
17 18 19 20 21 |
# File 'lib/wrf_forecast/forecast/suntime_text.rb', line 17 def initialize() coordinate = .station.coordinate @text = generate_sunrise_text(.start_date, coordinate).concat(", ") @text.concat(generate_sunset_text(.start_date, coordinate)) end |
Instance Attribute Details
#text ⇒ String (readonly)
Returns the part of the forcast text containing sunrise and sunset.
13 14 15 |
# File 'lib/wrf_forecast/forecast/suntime_text.rb', line 13 def text @text end |
Instance Method Details
#format_time(time) ⇒ String (private)
helper method to format the time from a Float to a timestamp with hh:mm
48 49 50 51 52 53 54 55 56 |
# File 'lib/wrf_forecast/forecast/suntime_text.rb', line 48 def format_time(time) hours = time.floor text = "" text.concat("0") if (hours < 10) text.concat("#{hours}").concat(":") minutes = (time.round(2) % 1 * 60).round(0) text.concat("0") if (minutes < 10) text.concat("#{minutes}") end |
#generate_sunrise_text(date, coordinate) ⇒ String (private)
method to calculate the sunrise time and the text part for the sunrise
29 30 31 32 33 |
# File 'lib/wrf_forecast/forecast/suntime_text.rb', line 29 def generate_sunrise_text(date, coordinate) sunrise = WrfLibrary::SunEquation.calculate_sunrise_time(date, coordinate.x, coordinate.y) text = I18n.t("forecast_text.suntime.sunrise") text.concat(format_time(sunrise)) end |
#generate_sunset_text(date, coordinate) ⇒ String (private)
method to calculate the sunset time and the text part for the sunset
39 40 41 42 43 |
# File 'lib/wrf_forecast/forecast/suntime_text.rb', line 39 def generate_sunset_text(date, coordinate) sunset = WrfLibrary::SunEquation.calculate_sunset_time(date, coordinate.x, coordinate.y) text = I18n.t("forecast_text.suntime.sunset") text.concat(format_time(sunset)) end |