Class: Nitlink::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/nitlink/parser.rb

Constant Summary collapse

/\A\s*<([^>]*)>(.*)/
RWS =
/[\x09\x20]+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/nitlink/parser.rb', line 14

def options
  @options
end

Instance Method Details

#parse(response, http_method = 'GET') ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nitlink/parser.rb', line 16

def parse(response, http_method = 'GET')
  @http_method = http_method
  @request_uri, @status, link_header, @content_location_header = ResponseNormalizer.new.(response)

  links = LinkCollection.new
  return links unless link_header

  unfolded_header = link_header.gsub(/\r?\n[\x20\x09]+/, '')
  link_strings = Splitter.new(unfolded_header).split_on_unquoted(',')

  parse_links(link_strings, links)
end