Class: WrfForecast::ForecastText

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(meta_data, forecast_repository, threshold_handler) ⇒ ForecastText

initialization the rehashed forecast data

Parameters:

  • meta_data (WrfMetaData)

    the meta data for the forecast

  • forecast_repository (ForecastRepository)

    the repository with

  • threshold_handler (ThresholdHandler)

    the handler with the indicators



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_textAirTemperatureText (readonly, private)

Returns the class generating the temperature forecast text.

Returns:

  • (AirTemperatureText)

    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

#bodyString (readonly)

Returns a copy of the forecast body text.

Returns:

  • (String)

    a copy of the forecast body text



13
14
15
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 13

def body
  @body
end

#headerString (readonly)

Returns a copy of the forecast header text.

Returns:

  • (String)

    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_textPressureText (readonly, private)

Returns the class generating the pressure forecast text.

Returns:

  • (PressureText)

    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_textRainText (readonly, private)

Returns the class generating the rain forecast text.

Returns:

  • (RainText)

    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_textSuntimeText (readonly, private)

Returns the class generating the suntime text.

Returns:

  • (SuntimeText)

    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

#warningsString (readonly)

Returns a the warning text.

Returns:

  • (String)

    a the warning text



15
16
17
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 15

def warnings
  @warnings
end

#wind_textWindText (readonly, private)

Returns the class generating the wind forecast text.

Returns:

  • (WindText)

    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_bodyObject (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

Parameters:

  • meta_data (WrfMetaData)

    the meta data for the 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_warningsObject (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_textString

method to create the complete forecast text

Returns:

  • (String)

    the combined 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

Parameters:

  • repository (ForecastRepository)

    the repository with the rehashed forecast data

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with the rehashed forecast data

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with the rehashed forecast data

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with the rehashed forecast data

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with the rehashed forecast data

  • handler (ThresholdHandler)

    the handler with the indicators



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