Class: WrfForecast::Text::AirTemperatureText

Inherits:
MeasurandText show all
Defined in:
lib/wrf_forecast/forecast/air_temperature_text.rb

Overview

This class generates the forecast text for the air temperature data of the forecast warnings: the hot day contains the summer day and can have a tropical night or frost day but exclude the ice day the ice day contains the frost day, both exclude tropical night

Instance Attribute Summary

Attributes inherited from MeasurandText

#extreme_values, #text, #thresholds, #warnings

Instance Method Summary collapse

Methods inherited from MeasurandText

#initialize, #is_threshold_active?

Constructor Details

This class inherits a constructor from WrfForecast::Text::MeasurandText

Instance Method Details

#create_temperature_textString (private)

method to generate the text with temperature values

Returns:

  • (String)

    the substring containing the temperature values and text conclusion



58
59
60
61
62
63
64
65
# File 'lib/wrf_forecast/forecast/air_temperature_text.rb', line 58

def create_temperature_text
  text = I18n.t("forecast_text.air_temperature.text_maximum")
  text.concat((@extreme_values.maximum - 273.15).ceil.to_s)
  text.concat(I18n.t("forecast_text.air_temperature.text_minimum"))
  text.concat((@extreme_values.minimum - 273.15).floor.to_s)
  text.concat(I18n.t("forecast_text.air_temperature.text_finish"))
  text
end

#create_warmth_textString (private)

method to generate the text about the day

Returns:

  • (String)

    the substring containing the temperature category



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wrf_forecast/forecast/air_temperature_text.rb', line 33

def create_warmth_text
  warmth = I18n.t("forecast_text.air_temperature.warmth_normal")
  if (is_threshold_active?(:ice_day))
    warmth = I18n.t("forecast_text.air_temperature.warmth_very_frosty")
  elsif (@thresholds[:frost_day].is_active)
    warmth = I18n.t("forecast_text.air_temperature.warmth_cold")
  end

  if (is_threshold_active?(:hot_day))
    warmth = I18n.t("forecast_text.air_temperature.warmth_hot")
  elsif (is_threshold_active?(:summer_day))
    warmth = I18n.t("forecast_text.air_temperature.warmth_summer")
  end

  warmth.concat(I18n.t("forecast_text.air_temperature.text_day"))
  if (@thresholds[:tropical_night].is_active)
    warmth.concat(I18n.t("forecast_text.air_temperature.warmth_tropical"))
    @warnings.concat("\n") if (!@warnings.empty?)
    @warnings.concat(@thresholds[:tropical_night].warning_text)
  end
  warmth
end

#generate_forecast_textObject (private)

method to generate the forecast text for the air temperature



15
16
17
18
19
20
# File 'lib/wrf_forecast/forecast/air_temperature_text.rb', line 15

def generate_forecast_text
  @text = I18n.t("forecast_text.air_temperature.text_start")
  @text.concat(create_warmth_text).concat(".")
  @text.concat(create_temperature_text)
  nil
end

#generate_warning_textObject (private)

method to generate the warning text for the measurand



23
24
25
26
27
28
29
# File 'lib/wrf_forecast/forecast/air_temperature_text.rb', line 23

def generate_warning_text
  if (@thresholds[:frost_day].is_active && !@thresholds[:ice_day].is_active)
    @warnings.concat("\n") if (!@warnings.empty?)
    @warnings.concat(@thresholds[:frost_day].warning_text)
  end  
  @warnings
end