Class: WrfForecast::Text::MeasurandText

Inherits:
Object
  • Object
show all
Defined in:
lib/wrf_forecast/forecast/measurand_text.rb

Overview

This abstract class serves as the prarent class to measurand specific forecast texts. It contains the resulting forecast text for the measurand based on the input data and the warnings specified in the corresponding threshold class.

Direct Known Subclasses

RainText, TemperatureText, WindText

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extreme_values, thresholds) ⇒ MeasurandText

initialization

Parameters:

  • extreme_values (ExtremeValues)

    the measurand extreme values

  • thresholds (BaseThreshold)

    the measurand threshold



19
20
21
22
23
24
25
26
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 19

def initialize(extreme_values, thresholds)
  @extreme_values = extreme_values
  @thresholds = thresholds
  @text = ""
  @warnings = ""
  generate_forecast_text
  generate_warning_text
end

Instance Attribute Details

#extreme_valuesExtremeValues (readonly, private)

Returns the measurand extreme values.

Returns:

  • (ExtremeValues)

    the measurand extreme values



31
32
33
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 31

def extreme_values
  @extreme_values
end

#textString (readonly)

Returns the forecast text for the measurand.

Returns:

  • (String)

    the forecast text for the measurand



12
13
14
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 12

def text
  @text
end

#thresholdsTemperatureThreshold (readonly, private)

Returns the measurand thresholds.

Returns:

  • (TemperatureThreshold)

    the measurand thresholds



33
34
35
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 33

def thresholds
  @thresholds
end

#warningsString (readonly)

Returns the warning text for the measurand.

Returns:

  • (String)

    the warning text for the measurand



14
15
16
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 14

def warnings
  @warnings
end

Instance Method Details

#generate_forecast_textObject (private)

abstract method to generate the forecast text for the measurand

Raises:

  • (NotImplementedError)

    if the child class does not implement this



47
48
49
50
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 47

def generate_forecast_text
  fail NotImplementedError, " Error: the subclass #{self.class} needs " \
       "to implement the method: generate_forecast_text from its base class".red
end

#generate_warning_textObject (private)

abstract method to generate the warning text for the measurand

Raises:

  • (NotImplementedError)

    if the child class does not implement this



54
55
56
57
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 54

def generate_warning_text
  fail NotImplementedError, " Error: the subclass #{self.class} needs " \
       "to implement the method: generate_warning_text from its base class".red
end

#is_threshold_active?(indicator) ⇒ Boolean (private)

method to determine if the threshold for the given indicator is active

Parameters:

  • indicator (Symbol)

    the given threshold indicator

Returns:

  • (Boolean)

    boolean if the thresolhd to the indicator is active



38
39
40
41
42
43
# File 'lib/wrf_forecast/forecast/measurand_text.rb', line 38

def is_threshold_active?(indicator)
  if (@thresholds[indicator].is_active)
    @warnings = @thresholds[indicator].warning_text
  end
  @thresholds[indicator].is_active
end