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
-
#air_temperature_text ⇒ AirTemperatureText
readonly
private
The class generating the temperature forecast text.
-
#body ⇒ String
readonly
A copy of the forecast body text.
-
#header ⇒ String
readonly
A copy of the forecast header text.
-
#pressure_text ⇒ PressureText
readonly
private
The class generating the pressure forecast text.
-
#rain_text ⇒ RainText
readonly
private
The class generating the rain forecast text.
-
#suntime_text ⇒ SuntimeText
readonly
private
The class generating the suntime 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_air_temperature_text(repository, handler) ⇒ Object
private
method to create the text for the air temperature.
-
#initialize_apparent_temperature_text(repository, handler) ⇒ Object
private
method to create the text for the apparent temperature.
-
#initialize_pressure_text(repository, handler) ⇒ Object
private
method to create the text for the pressure.
-
#initialize_rain_text(repository, handler) ⇒ Object
private
method to create the text for the precipitation.
-
#initialize_wind_text(repository, handler) ⇒ Object
private
method to create the text for the wind.
Constructor Details
#initialize(meta_data, forecast_repository, threshold_handler) ⇒ ForecastText
initialization the rehashed forecast data
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 22 def initialize(, forecast_repository, threshold_handler) initialize_pressure_text(forecast_repository, threshold_handler) initialize_air_temperature_text(forecast_repository, threshold_handler) initialize_apparent_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
#air_temperature_text ⇒ AirTemperatureText (readonly, private)
Returns the class generating the temperature forecast text.
47 48 49 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 47 def air_temperature_text @air_temperature_text end |
#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 |
#pressure_text ⇒ PressureText (readonly, private)
Returns the class generating the pressure forecast text.
45 46 47 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 45 def pressure_text @pressure_text end |
#rain_text ⇒ RainText (readonly, private)
Returns the class generating the rain forecast text.
51 52 53 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 51 def rain_text @rain_text end |
#suntime_text ⇒ SuntimeText (readonly, private)
Returns the class generating the suntime text.
53 54 55 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 53 def suntime_text @suntime_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.
49 50 51 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 49 def wind_text @wind_text end |
Instance Method Details
#create_body ⇒ Object (private)
method to create the body text for the text forecast
68 69 70 71 72 73 74 75 76 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 68 def create_body @body = @suntime_text.text.concat("\n") @body.concat(@air_temperature_text.text).concat("\n") @body.concat(@pressure_text.text).concat("\n") @body.concat(@wind_text.text).concat("\n") @body.concat(@rain_text.text).concat("\n") @body.concat(@apparent_temperature_text.text) nil end |
#create_header(meta_data) ⇒ Object (private)
method to create the header line for the text forecast
57 58 59 60 61 62 63 64 65 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 57 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 79 def create_warnings @warnings= "" @warnings.concat("\n") if (!@air_temperature_text.warnings.empty?) @warnings.concat(@air_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) @warnings.concat("\n") if (!@apparent_temperature_text.warnings.empty?) @warnings.concat(@apparent_temperature_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
36 37 38 39 40 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 36 def get_complete_text text = @header.dup text.concat(".\n\n") text.concat(@body) end |
#initialize_air_temperature_text(repository, handler) ⇒ Object (private)
method to create the text for the air temperature
121 122 123 124 125 126 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 121 def initialize_air_temperature_text(repository, handler) extreme_values = repository.extreme_values[:air_temperature] threshold = handler.air_temperature_threshold.indicators @air_temperature_text = WrfForecast::Text::AirTemperatureText.new(extreme_values, threshold) nil end |
#initialize_apparent_temperature_text(repository, handler) ⇒ Object (private)
method to create the text for the apparent temperature
111 112 113 114 115 116 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 111 def initialize_apparent_temperature_text(repository, handler) extreme_values = repository.extreme_values[:apparent_temperature] threshold = handler.apparent_temperature_threshold.indicators @apparent_temperature_text = WrfForecast::Text::ApparentTemperatureText.new(extreme_values, threshold) nil end |
#initialize_pressure_text(repository, handler) ⇒ Object (private)
method to create the text for the pressure
100 101 102 103 104 105 106 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 100 def initialize_pressure_text(repository, handler) extreme_values = repository.extreme_values[:pressure] pressure_data = repository.forecast_data[:pressure] threshold = handler.pressure_threshold.indicators @pressure_text = WrfForecast::Text::PressureText.new(extreme_values, pressure_data, threshold) nil end |
#initialize_rain_text(repository, handler) ⇒ Object (private)
method to create the text for the precipitation
142 143 144 145 146 147 148 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 142 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_wind_text(repository, handler) ⇒ Object (private)
method to create the text for the wind
131 132 133 134 135 136 137 |
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 131 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 |