Class: MaxPage::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/max_page/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/max_page/metric.rb', line 3

def block
  @block
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/max_page/metric.rb', line 3

def description
  @description
end

#groupObject

Returns the value of attribute group.



3
4
5
# File 'lib/max_page/metric.rb', line 3

def group
  @group
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/max_page/metric.rb', line 3

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/max_page/metric.rb', line 4

def value
  @value
end

#verifyObject

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

Returns:

  • (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

#runObject



6
7
8
# File 'lib/max_page/metric.rb', line 6

def run
  @value = block.call
end

#verify?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/max_page/metric.rb', line 10

def verify?
  !!verify
end