Class: WrfForecast::ForecastText
- Inherits:
-
Object
- Object
- WrfForecast::ForecastText
- Defined in:
- lib/wrf_forecast/forecast/forecast_text.rb
Overview
This class handles the creation of the combined forecast text for the given input
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
A copy of the forecast body text.
-
#header ⇒ String
readonly
A copy of the forecast header text.
-
#rain_text ⇒ RainText
readonly
private
The class generating the rain forecast text.
-
#suntime_text ⇒ SuntimeText
readonly
private
The class generating the suntime text.
-
#temperature_text ⇒ TemperatureText
readonly
private
The class generating the temperature forecast text.
-
#warnings ⇒ String
readonly
A the warning text.
-
#wind_text ⇒ WindText
readonly
private
The class generating the wind forecast text.
Instance Method Summary collapse
-
#create_body ⇒ Object
private
method to create the body text for the text forecast.
-
#create_header(meta_data) ⇒ Object
private
method to create the header line for the text forecast.
-
#create_warnings ⇒ Object
private
method to create the warning text for the forecast.
-
#get_complete_text ⇒ String
method to create the complete forecast text.
-
#initialize(meta_data, forecast_repository, threshold_handler) ⇒ ForecastText
constructor
initialization the rehashed forecast data.
-
#initialize_rain_text(repository, handler) ⇒ Object
private
method to create the text for the precipitation the rehashed forecast data.
-
#initialize_temperature_text(repository, handler) ⇒ Object
private
method to create the text for the air temperature the rehashed forecast data.
-
#initialize_wind_text(repository, handler) ⇒ Object
private
method to create the text for the wind the rehashed forecast data.
Constructor Details
#initialize(meta_data, forecast_repository, threshold_handler) ⇒ ForecastText
initialization the rehashed forecast data
22 23 24 25 26 27 28 29 30 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 22 def initialize(, forecast_repository, threshold_handler) initialize_temperature_text(forecast_repository, threshold_handler) initialize_wind_text(forecast_repository, threshold_handler) initialize_rain_text(forecast_repository, threshold_handler) @suntime_text = WrfForecast::Text::SuntimeText.new() create_header() create_body create_warnings end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns a copy of the forecast body text.
13 14 15 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 13 def body @body end |
#header ⇒ String (readonly)
Returns a copy of the forecast header text.
11 12 13 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 11 def header @header end |
#rain_text ⇒ RainText (readonly, private)
Returns the class generating the rain forecast text.
47 48 49 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 47 def rain_text @rain_text end |
#suntime_text ⇒ SuntimeText (readonly, private)
Returns the class generating the suntime text.
49 50 51 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 49 def suntime_text @suntime_text end |
#temperature_text ⇒ TemperatureText (readonly, private)
Returns the class generating the temperature forecast text.
43 44 45 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 43 def temperature_text @temperature_text end |
#warnings ⇒ String (readonly)
Returns a the warning text.
15 16 17 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 15 def warnings @warnings end |
#wind_text ⇒ WindText (readonly, private)
Returns the class generating the wind forecast text.
45 46 47 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 45 def wind_text @wind_text end |
Instance Method Details
#create_body ⇒ Object (private)
method to create the body text for the text forecast
64 65 66 67 68 69 70 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 64 def create_body @body = @suntime_text.text.concat("\n") @body.concat(@temperature_text.text).concat("\n") @body.concat(@wind_text.text).concat("\n") @body.concat(@rain_text.text) nil end |
#create_header(meta_data) ⇒ Object (private)
method to create the header line for the text forecast
53 54 55 56 57 58 59 60 61 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 53 def create_header() station = .station start_date = .start_date @header = I18n.t("forecast_text.main.header_start") @header.concat(station.name) @header.concat(I18n.t("forecast_text.main.header_conn")) @header.concat(start_date.to_s) nil end |
#create_warnings ⇒ Object (private)
method to create the warning text for the forecast
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 73 def create_warnings @warnings= "" @warnings.concat("\n") if (!@temperature_text.warnings.empty?) @warnings.concat(@temperature_text.warnings) @warnings.concat("\n") if (!@wind_text.warnings.empty?) @warnings.concat(@wind_text.warnings) @warnings.concat("\n") if (!@rain_text.warnings.empty?) @warnings.concat(@rain_text.warnings) if (@warnings.empty?) @warnings = "#{I18n.t("forecast_text.main.warnings")}-" else @warnings = I18n.t("forecast_text.main.warnings").concat(@warnings) end nil end |
#get_complete_text ⇒ String
method to create the complete forecast text
34 35 36 37 38 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 34 def get_complete_text text = @header.dup text.concat(".\n\n") text.concat(@body) end |
#initialize_rain_text(repository, handler) ⇒ Object (private)
method to create the text for the precipitation the rehashed forecast data
116 117 118 119 120 121 122 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 116 def initialize_rain_text(repository, handler) extreme_values = repository.extreme_values[:rain] hourly_rain = repository.hourly_rain threshold = handler.rain_threshold.indicators @rain_text = WrfForecast::Text::RainText.new(extreme_values, hourly_rain, threshold) nil end |
#initialize_temperature_text(repository, handler) ⇒ Object (private)
method to create the text for the air temperature the rehashed forecast data
93 94 95 96 97 98 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 93 def initialize_temperature_text(repository, handler) extreme_values = repository.extreme_values[:air_temperature] threshold = handler.temperature_threshold.indicators @temperature_text = WrfForecast::Text::TemperatureText.new(extreme_values, threshold) nil end |
#initialize_wind_text(repository, handler) ⇒ Object (private)
method to create the text for the wind the rehashed forecast data
104 105 106 107 108 109 110 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 104 def initialize_wind_text(repository, handler) extreme_values = repository.extreme_values[:wind_speed] prevalent_direction = repository.prevalent_direction threshold = handler.wind_threshold.indicators @wind_text = WrfForecast::Text::WindText.new(extreme_values, prevalent_direction, threshold) nil end |