Class: Pantheios::FrontEnds::ThresholdFrontEnd
- Inherits:
-
Object
- Object
- Pantheios::FrontEnds::ThresholdFrontEnd
- Defined in:
- lib/pantheios/front_ends/threshold_front_end.rb
Overview
A class that fulfils the Pantheios FrontEnd protocol that implements severity_logged?
based on a threshold specified to the initialiser
NOTE: The FrontEnd protocol is implemented by a class that provides the instance method severity_logged?(severity : Object)
Instance Attribute Summary collapse
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
-
#initialize(threshold_severity, **options) ⇒ ThresholdFrontEnd
constructor
Initialises the instance.
-
#severity_logged?(severity) ⇒ Boolean
Determines whether a given severity is logged.
Constructor Details
#initialize(threshold_severity, **options) ⇒ ThresholdFrontEnd
Initialises the instance
Signature
-
Parameters:
-
threshold_severity
[ ::Symbol ] The threshold severity
-
-
Options:
-
value_lookup_map
[ ::Hash ] A map that is used to lookupseverity
values (that are not::Integer
) inseverity_logged?
. May benil
, in which case::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
is used
-
-
Exceptions:
-
::TypeError
raised if a value given for:value_lookup_map
is not a ::hash
-
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pantheios/front_ends/threshold_front_end.rb', line 80 def initialize(threshold_severity, **) m = [:value_lookup_map] raise TypeError, "value given for :value_lookup_map must be a #{::Hash}" if m && !m.respond_to?(:to_hash) if m @value_lookup_map = m @relativity_lookup_map = ::Hash.new(:relative) else @value_lookup_map = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES @relativity_lookup_map = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_RELATIVE end self.threshold = threshold_severity end |
Instance Attribute Details
#threshold ⇒ Object
Returns the value of attribute threshold.
139 140 141 |
# File 'lib/pantheios/front_ends/threshold_front_end.rb', line 139 def threshold @threshold end |
Instance Method Details
#severity_logged?(severity) ⇒ Boolean
Determines whether a given severity is logged
Signature
-
Parameters:
severity
-
The severity level, which should be a known log
severity symbol or an integral equivalent
-
Returns: a
truey
value if the severity should be logged; afalsey
value otherwise
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pantheios/front_ends/threshold_front_end.rb', line 110 def severity_logged? severity case severity when ::Integer v = severity else v = @value_lookup_map[severity] or warn "unknown severity level '#{severity}' (#{severity.class})" end return true if v.nil? v <= @threshold_v end |