Class: Interpol::StatusCodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/interpol/endpoint.rb

Overview

Holds the acceptable status codes for an enpoint entry Acceptable status code are either exact status codes (200, 404, etc) or partial status codes (2xx, 3xx, 4xx, etc). Currently, partial status codes can only be a digit followed by two lower-case x’s.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codes) ⇒ StatusCodeMatcher

Returns a new instance of StatusCodeMatcher.



230
231
232
233
234
# File 'lib/interpol/endpoint.rb', line 230

def initialize(codes)
  codes = ["xxx"] if Array(codes).empty?
  @code_strings = codes
  validate!
end

Instance Attribute Details

#code_stringsObject (readonly)

Returns the value of attribute code_strings.



228
229
230
# File 'lib/interpol/endpoint.rb', line 228

def code_strings
  @code_strings
end

Instance Method Details

#example_status_codeObject



240
241
242
243
244
245
246
# File 'lib/interpol/endpoint.rb', line 240

def example_status_code
  example_status_code = "200"
  code_strings.first.chars.each_with_index do |char, index|
    example_status_code[index] = char if char != 'x'
  end
  example_status_code
end

#matches?(status_code) ⇒ Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/interpol/endpoint.rb', line 236

def matches?(status_code)
  code_regexes.any? { |re| re =~ status_code.to_s }
end