Class: Genderize::Io::Parser::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/genderize/io/parser/header.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, strict: true) ⇒ Header

Returns a new instance of Header.



10
11
12
13
14
# File 'lib/genderize/io/parser/header.rb', line 10

def initialize(response, strict: true)
  @response = response
  @strict = strict
  @headers = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



26
27
28
# File 'lib/genderize/io/parser/header.rb', line 26

def method_missing(sym, *)
  detect_multi_value_keys(sym) || super
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/genderize/io/parser/header.rb', line 8

def headers
  @headers
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/genderize/io/parser/header.rb', line 8

def response
  @response
end

#strictObject (readonly)

Returns the value of attribute strict.



8
9
10
# File 'lib/genderize/io/parser/header.rb', line 8

def strict
  @strict
end

Class Method Details

.parse(response, strict: true) ⇒ Object



16
17
18
19
20
# File 'lib/genderize/io/parser/header.rb', line 16

def self.parse(response, strict: true)
  klass = new(response, strict: strict)
  klass.parse
  klass
end

Instance Method Details

#parseObject



22
23
24
# File 'lib/genderize/io/parser/header.rb', line 22

def parse
  @headers = @response.split(/\\r\\n|\n|\r/)
end

#respond_to_missing?(sym) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/genderize/io/parser/header.rb', line 30

def respond_to_missing?(sym, *)
  detect_multi_value_keys(sym) || super
end

#response_codeObject



34
35
36
# File 'lib/genderize/io/parser/header.rb', line 34

def response_code
  @headers[0].match(%r{HTTP/\d\.\d (\d{3}.*)})[1]
end

#versionObject



38
39
40
# File 'lib/genderize/io/parser/header.rb', line 38

def version
  @headers[0].match(%r{HTTP/\d\.\d})[0]
end