Class: MaxPage::Metric
- Inherits:
-
Object
- Object
- MaxPage::Metric
- Defined in:
- lib/max_page/metric.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#description ⇒ Object
Returns the value of attribute description.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#verify ⇒ Object
Returns the value of attribute verify.
Instance Method Summary collapse
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/max_page/metric.rb', line 3 def block @block end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/max_page/metric.rb', line 3 def description @description end |
#group ⇒ Object
Returns the value of attribute group.
3 4 5 |
# File 'lib/max_page/metric.rb', line 3 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/max_page/metric.rb', line 3 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/max_page/metric.rb', line 4 def value @value end |
#verify ⇒ Object
Returns the value of attribute verify.
3 4 5 |
# File 'lib/max_page/metric.rb', line 3 def verify @verify end |
Instance Method Details
#ok? ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/max_page/metric.rb', line 23 def ok? return true if not verify? run if not value if verify.is_a? Hash validations = verify.map do |rule_name, rule_value| case rule_name when :min then value.to_i >= rule_value when :max then value.to_i <= rule_value else raise "Invalid rule: #{rule_name}" end end validations.all? true else value == verify end end |
#run ⇒ Object
6 7 8 |
# File 'lib/max_page/metric.rb', line 6 def run @value = block.call end |
#verify? ⇒ Boolean
10 11 12 |
# File 'lib/max_page/metric.rb', line 10 def verify? !!verify end |