Class: Lecter::FormatterHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/lecter/formatter_headers.rb

Constant Summary collapse

WRONG_HEADERS_MSG =
'Wrong headers'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ FormatterHeaders

Returns a new instance of FormatterHeaders.



8
9
10
# File 'lib/lecter/formatter_headers.rb', line 8

def initialize(headers)
  @dirty_headers = headers
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



6
7
8
# File 'lib/lecter/formatter_headers.rb', line 6

def error_message
  @error_message
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/lecter/formatter_headers.rb', line 6

def result
  @result
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
# File 'lib/lecter/formatter_headers.rb', line 12

def call
  @result = dirty_headers
            .split(',')
            .map { |header_with_value| header_with_value.split('=') }
            .to_h
rescue StandardError
  @error_message = WRONG_HEADERS_MSG
  false
end