Class: FlexStationData::ValueQuality

Inherits:
Object
  • Object
show all
Includes:
Callable
Defined in:
lib/flex_station_data/services/value_quality.rb

Defined Under Namespace

Classes: Bad, Good

Instance Attribute Summary collapse

Instance Method Summary collapse

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, **_options)
  @value = value
  @threshold = threshold
end

Instance Attribute Details

#thresholdObject (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

#valueObject (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

Returns:

  • (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

#callObject



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

Returns:

  • (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

Returns:

  • (Boolean)


47
48
49
# File 'lib/flex_station_data/services/value_quality.rb', line 47

def no_data?
  value.blank?
end

#saturated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/flex_station_data/services/value_quality.rb', line 51

def saturated?
  value == "#SAT"
end