Class: FactMetrics::Metric
- Inherits:
-
Object
- Object
- FactMetrics::Metric
- Defined in:
- lib/fact_metrics/metric.rb
Constant Summary collapse
- BLANK =
Class.new do def method_missing(m, *args, &block) if respond_to_missing?(m) Metric.new(0, {precision: 0}) end end def respond_to_missing?(m) /_metric$/.match?(m) end end
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #display_value ⇒ Object
-
#initialize(value, options) ⇒ Metric
constructor
A new instance of Metric.
- #name ⇒ Object
- #precision ⇒ Object
- #unit ⇒ Object
Constructor Details
#initialize(value, options) ⇒ Metric
Returns a new instance of Metric.
16 17 18 |
# File 'lib/fact_metrics/metric.rb', line 16 def initialize(value, ) @value, @options = value, end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/fact_metrics/metric.rb', line 2 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
2 3 4 |
# File 'lib/fact_metrics/metric.rb', line 2 def value @value end |
Instance Method Details
#display_value ⇒ Object
24 25 26 |
# File 'lib/fact_metrics/metric.rb', line 24 def display_value (value || 0).round(precision) end |
#name ⇒ Object
20 21 22 |
# File 'lib/fact_metrics/metric.rb', line 20 def name [:name].humanize end |
#precision ⇒ Object
28 29 30 |
# File 'lib/fact_metrics/metric.rb', line 28 def precision [:precision] || 1 end |
#unit ⇒ Object
32 33 34 |
# File 'lib/fact_metrics/metric.rb', line 32 def unit [:unit] || "" end |