Class: WrfForecast::Text::RainText

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

Overview

This class generates the forecast text for the rain data of the forecast warings: all hourly warnings contain the lesser warnings as a subset, so only the worst hourly warning needs to be shown, the continous warning will be shown if the rain amount sums up over 6 hours, if a hourly event also accours during the time both are shown

Instance Attribute Summary collapse

Attributes inherited from MeasurandText

#extreme_values, #text, #thresholds, #warnings

Instance Method Summary collapse

Methods inherited from MeasurandText

#is_threshold_active?

Constructor Details

#initialize(extreme_values, hourly_rain, thresholds) ⇒ RainText

initialization

Parameters:

  • extreme_values (ExtremeValues)

    the hourly rain extreme values

  • hourly_rain (Array)

    the hourly rain sums

  • thresholds (RainThreshold)

    the rain threshold



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

def initialize(extreme_values, hourly_rain, thresholds)
  @hourly_rain = hourly_rain
  calculate_rainsum
  super(extreme_values, thresholds)
end

Instance Attribute Details

#hourly_rainArray (readonly, private)

Returns the hourly rain sums.

Returns:

  • (Array)

    the hourly rain sums



24
25
26
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 24

def hourly_rain
  @hourly_rain
end

#rain_sumFloat (readonly, private)

Returns the daily rain sum.

Returns:

  • (Float)

    the daily rain sum



26
27
28
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 26

def rain_sum
  @rain_sum
end

Instance Method Details

#calculate_rainsumObject (private)

method to calculate the total rain of the day



100
101
102
103
104
105
106
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 100

def calculate_rainsum
  @rain_sum = 0
  @hourly_rain.each { |value|
    @rain_sum += value
  }
  nil
end

#create_intensity_textString (private)

method to generate the text about the day

Returns:

  • (String)

    the substring containing the rain intensity



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 48

def create_intensity_text
  intensity = I18n.t("forecast_text.rain.intensity_normal")
  if (is_threshold_active?(:extreme_rain))
    intensity = I18n.t("forecast_text.rain.intensity_extreme")
  elsif (is_threshold_active?(:heavy_rain))
    intensity = I18n.t("forecast_text.rain.intensity_heavy")
  elsif (is_threshold_active?(:strong_rain))
    intensity = I18n.t("forecast_text.rain.intensity_strong")
  end

  if (@thresholds[:continous_rain].is_active)
    intensity = I18n.t("forecast_text.rain.intensity_continous")
    @warnings.concat"\n" if (!@warnings.empty?)
    @warnings.concat(@thresholds[:continous_rain].warning_text)
  end
  return intensity
end

#create_rain_textString (private)

method to generate the text with rain values

Returns:

  • (String)

    the substring containing the precipitation amount



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 68

def create_rain_text
  text = I18n.t("forecast_text.rain.text_maximum")
  if (@thresholds[:continous_rain].is_active)
    text.concat(@rain_sum.ceil.to_s)
    text.concat(I18n.t("forecast_text.rain.text_continous"))
  else
    text.concat(@extreme_values.maximum.round(1).to_s)
    text.concat(I18n.t("forecast_text.rain.text_amount_hour"))
    text.concat(@rain_sum.ceil.to_s)
    text.concat(I18n.t("forecast_text.rain.text_amount_day"))
  end

  text.concat(I18n.t("forecast_text.rain.text_period_start"))
  if (@extreme_values.minimum.round(5) == 0.0)
    text.concat(I18n.t("forecast_text.rain.text_period_some_dry"))
  else
    text.concat(I18n.t("forecast_text.rain.text_period_no_dry"))
  end
  text.concat(I18n.t("forecast_text.rain.text_period_finish"))
  return text
end

#generate_forecast_textObject (private)

method to generate the forecast text for the rain



29
30
31
32
33
34
35
36
37
38
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 29

def generate_forecast_text
  if (!shall_it_rain?)
    @text = I18n.t("forecast_text.rain.no_rain")
  else
    @text = I18n.t("forecast_text.rain.rain_start")
    @text.concat(create_intensity_text)
    @text.concat(create_rain_text)
  end
  nil
end

#generate_warning_textString (private)

method to generate the warning text for the measurand

Returns:

  • (String)

    the warning text



42
43
44
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 42

def generate_warning_text
  @warnings
end

#shall_it_rain?boolean (private)

method to check if it should rain in the forecast time

Returns:

  • (boolean)

    the information if it rains during the day



92
93
94
95
96
97
# File 'lib/wrf_forecast/forecast/rain_text.rb', line 92

def shall_it_rain?
  @hourly_rain.each { |value|
    return true if (value > 0.05)
  }
  return false
end