Class: Pantheios::FrontEnds::ThresholdFrontEnd

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 lookup severity values (that are not ::Integer) in severity_logged?. May be nil, 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

Raises:

  • (TypeError)


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, **options)

	m = options[: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

#thresholdObject

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; a falsey value otherwise

Returns:

  • (Boolean)


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