Class: FlexStationData::ValueQuality
- Inherits:
-
Object
- Object
- FlexStationData::ValueQuality
- Includes:
- Callable
- Defined in:
- lib/flex_station_data/services/value_quality.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #below_threshold? ⇒ Boolean
- #call ⇒ Object
-
#initialize(value, threshold: nil, **_options) ⇒ ValueQuality
constructor
A new instance of ValueQuality.
- #invalid? ⇒ Boolean
- #no_data? ⇒ Boolean
- #saturated? ⇒ Boolean
Constructor Details
#initialize(value, threshold: nil, **_options) ⇒ ValueQuality
Returns a new instance of ValueQuality.
42 43 44 45 |
# File 'lib/flex_station_data/services/value_quality.rb', line 42 def initialize(value, threshold: nil, **) @value = value @threshold = threshold end |
Instance Attribute Details
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
40 41 42 |
# File 'lib/flex_station_data/services/value_quality.rb', line 40 def threshold @threshold end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
40 41 42 |
# File 'lib/flex_station_data/services/value_quality.rb', line 40 def value @value end |
Instance Method Details
#below_threshold? ⇒ Boolean
59 60 61 |
# File 'lib/flex_station_data/services/value_quality.rb', line 59 def below_threshold? threshold.present? && value.is_a?(Numeric) && value < threshold end |
#call ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/flex_station_data/services/value_quality.rb', line 63 def call if no_data? Bad.new("No data") elsif saturated? Bad.new("Saturated") elsif invalid? Bad.new("Invalid data") elsif below_threshold? Bad.new("Below threshold") else Good.instance end end |
#invalid? ⇒ Boolean
55 56 57 |
# File 'lib/flex_station_data/services/value_quality.rb', line 55 def invalid? !(no_data? || saturated? || value.is_a?(Numeric)) end |
#no_data? ⇒ Boolean
47 48 49 |
# File 'lib/flex_station_data/services/value_quality.rb', line 47 def no_data? value.blank? end |
#saturated? ⇒ Boolean
51 52 53 |
# File 'lib/flex_station_data/services/value_quality.rb', line 51 def saturated? value == "#SAT" end |