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
# 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

#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

#rain_textRainText (readonly, private)

Returns the class generating the rain forecast text.

Returns:

  • (RainText)

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

Returns the class generating the suntime text.

Returns:

  • (SuntimeText)

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

Returns the class generating the temperature forecast text.

Returns:

  • (TemperatureText)

    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

#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



45
46
47
# File 'lib/wrf_forecast/forecast/forecast_text.rb', line 45

def wind_text
  @wind_text
end

Instance Method Details

#create_bodyObject (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

Parameters:

  • meta_data (WrfMetaData)

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

method to create the complete forecast text

Returns:

  • (String)

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

Parameters:

  • repository (ForecastRepository)

    the repository with

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with

  • handler (ThresholdHandler)

    the handler with the indicators



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

Parameters:

  • repository (ForecastRepository)

    the repository with

  • handler (ThresholdHandler)

    the handler with the indicators



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