Class: WrfForecast::Text::WindText

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

Overview

This class generates the forecast text for the wind speed and direction of the forecast warnings: all lesser warnings are a subset of the highest warning, that means only the worst warning needs to be shown, that can be done during text creation

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, prevalent_direction, thresholds) ⇒ WindText

initialization

Parameters:

  • extreme_values (ExtremeValues)

    the wind extreme values

  • prevalent_direction (Symbol)

    the prevalent wind direction

  • thresholds (WindThreshold)

    the wind threshold



17
18
19
20
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 17

def initialize(extreme_values, prevalent_direction, thresholds)
  @prevalent_direction = prevalent_direction
  super(extreme_values, thresholds)
end

Instance Attribute Details

#prevalent_directionSymbol (readonly, private)

Returns the prevalent wind direction.

Returns:

  • (Symbol)

    the prevalent wind direction



25
26
27
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 25

def prevalent_direction
  @prevalent_direction
end

Instance Method Details

#create_prevalent_direction_textObject (private)

method to create the text for the prevalent wind direction



72
73
74
75
76
77
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 72

def create_prevalent_direction_text
  if (@prevalent_direction == nil)
    return I18n.t("forecast_text.wind.direction_circular")
  end
  return WrfForecast::Directions.new().get_direction_string(@prevalent_direction)
end

#create_strength_textObject (private)

method to generate the text about the day



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 42

def create_strength_text
  wind_strength = I18n.t("forecast_text.wind.strength_normal")
  if (is_threshold_active?(:hurricane_day))
   wind_strength = I18n.t("forecast_text.wind.strength_extremly_stormy")
  elsif (is_threshold_active?(:storm_day))
    wind_strength = I18n.t("forecast_text.wind.strength_very_stormy")
  elsif (is_threshold_active?(:storm_squall_day))
    wind_strength = I18n.t("forecast_text.wind.strength_stormy")
  elsif (is_threshold_active?(:squall_day))
    wind_strength = I18n.t("forecast_text.wind.strength_squall")
  elsif (is_threshold_active?(:windy_day))
    wind_strength = I18n.t("forecast_text.wind.strength_windy")
  end
  return wind_strength
end

#create_wind_textObject (private)

method to generate the text with wind values



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 59

def create_wind_text
  text = I18n.t("forecast_text.wind.text_maximum")
  text.concat((@extreme_values.maximum * 3.6).ceil.to_s)
  text.concat(I18n.t("forecast_text.wind.text_maximum_unit"))
  text.concat(create_prevalent_direction_text)
  text.concat(I18n.t("forecast_text.wind.text_mean"))
  mean = (@extreme_values.maximum + @extreme_values.minimum) / 2.0
  text.concat((mean * 3.6).ceil.to_s)
  text.concat(I18n.t("forecast_text.wind.text_finish"))
  return text
end

#generate_forecast_textObject (private)

method to generate the forecast text for the wind



28
29
30
31
32
33
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 28

def generate_forecast_text
  @text = I18n.t("forecast_text.wind.text_start")
  @text.concat(create_strength_text)
  @text.concat(create_wind_text)
  nil
end

#generate_warning_textString (private)

method to generate the warning text for the measurand

Returns:

  • (String)

    the warning text



37
38
39
# File 'lib/wrf_forecast/forecast/wind_text.rb', line 37

def generate_warning_text
  @warnings
end