Class: MeterBox::Meter
- Inherits:
-
Object
- Object
- MeterBox::Meter
- Defined in:
- lib/meter_box/meter.rb
Constant Summary collapse
- AGGREGATIONS =
%i[sum count latest max min mean count_distinct].freeze
Instance Attribute Summary collapse
-
#aggregation ⇒ Object
readonly
Returns the value of attribute aggregation.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #declared_keys ⇒ Object
-
#initialize(name:, dimensions:, aggregation: :sum) ⇒ Meter
constructor
A new instance of Meter.
- #validate_dimensions!(supplied) ⇒ Object
Constructor Details
#initialize(name:, dimensions:, aggregation: :sum) ⇒ Meter
Returns a new instance of Meter.
9 10 11 12 13 14 15 16 17 |
# File 'lib/meter_box/meter.rb', line 9 def initialize(name:, dimensions:, aggregation: :sum) @name = name.to_sym @dimensions = dimensions.transform_keys(&:to_sym) @aggregation = aggregation.to_sym unless AGGREGATIONS.include?(@aggregation) raise ArgumentError, "unknown aggregation :#{@aggregation} for meter '#{@name}' (allowed: #{AGGREGATIONS.inspect})" end end |
Instance Attribute Details
#aggregation ⇒ Object (readonly)
Returns the value of attribute aggregation.
7 8 9 |
# File 'lib/meter_box/meter.rb', line 7 def aggregation @aggregation end |
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
7 8 9 |
# File 'lib/meter_box/meter.rb', line 7 def dimensions @dimensions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/meter_box/meter.rb', line 7 def name @name end |
Instance Method Details
#declared_keys ⇒ Object
19 20 21 |
# File 'lib/meter_box/meter.rb', line 19 def declared_keys @dimensions.keys end |
#validate_dimensions!(supplied) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/meter_box/meter.rb', line 23 def validate_dimensions!(supplied) supplied = supplied.transform_keys(&:to_sym) check_required!(supplied) check_unknown_keys!(supplied) check_values!(supplied) end |