Class: Metricdeck::MetricCardService
- Inherits:
-
Object
- Object
- Metricdeck::MetricCardService
- Defined in:
- lib/metricdeck/metric_card_service.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #available_calculators ⇒ Object
- #available_card_types ⇒ Object
- #get_cards(context, card_types = nil) ⇒ Object
-
#initialize(namespace: nil) ⇒ MetricCardService
constructor
A new instance of MetricCardService.
Constructor Details
#initialize(namespace: nil) ⇒ MetricCardService
Returns a new instance of MetricCardService.
7 8 9 |
# File 'lib/metricdeck/metric_card_service.rb', line 7 def initialize(namespace: nil) @namespace = namespace || default_namespace end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/metricdeck/metric_card_service.rb', line 5 def namespace @namespace end |
Instance Method Details
#available_calculators ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/metricdeck/metric_card_service.rb', line 19 def available_calculators calculators = [] namespace.constants.each do |const_name| const = namespace.const_get(const_name) next unless const.is_a?(Class) && const.included_modules.include?(Metricdeck::Calculators::BaseCalculator) && const_name.to_s.end_with?('Calculator') calculators << const.new end calculators end |
#available_card_types ⇒ Object
35 36 37 |
# File 'lib/metricdeck/metric_card_service.rb', line 35 def available_card_types available_calculators.map { |c| c.card_id.to_sym } end |
#get_cards(context, card_types = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/metricdeck/metric_card_service.rb', line 11 def get_cards(context, card_types = nil) calculators = available_calculators calculators = calculators.select { |c| card_types.include?(c.card_id.to_sym) } if card_types.present? calculators.map { |calculator| calculator.calculate(context) } end |