Class: WebMonitor::ResponseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/web-monitor/response_validator.rb

Overview

Validate response time and status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, status, config) ⇒ ResponseValidator

Returns a new instance of ResponseValidator.



6
7
8
9
# File 'lib/web-monitor/response_validator.rb', line 6

def initialize(time, status, config)
  @time, @status = time.to_f, status.to_i
  @limit = config.response_time_limit
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/web-monitor/response_validator.rb', line 4

def status
  @status
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'lib/web-monitor/response_validator.rb', line 4

def time
  @time
end

Instance Method Details

#error_msgObject



15
16
17
18
# File 'lib/web-monitor/response_validator.rb', line 15

def error_msg
  return "Status=#{@status}" unless validate_status
  return "Time=%.1fs" % @time unless validate_time
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/web-monitor/response_validator.rb', line 11

def valid?
  validate_status and validate_time
end