Class: Restify::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/restify/link.rb

Overview

A Link represents a single entry from the Link header of a HTTP response.

Constant Summary collapse

REGEXP_URI =
/<[^>]*>\s*/.freeze
REGEXP_PAR =
/;\s*\w+\s*=\s*/i.freeze
REGEXP_QUT =
/"[^"]*"\s*/.freeze
REGEXP_ARG =
/\w+\s*/i.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, metadata = {}) ⇒ Link

Returns a new instance of Link.



22
23
24
25
# File 'lib/restify/link.rb', line 22

def initialize(uri,  = {})
  @uri      = uri
  @metadata = 
end

Instance Attribute Details

#metadataHash<String, String> (readonly)

Link metadata like “rel” if specified.

Returns:

  • (Hash<String, String>)

    Metadata.



20
21
22
# File 'lib/restify/link.rb', line 20

def 
  @metadata
end

#uriString (readonly)

Extract URI string.

Returns:

  • (String)

    URI string.



14
15
16
# File 'lib/restify/link.rb', line 14

def uri
  @uri
end

Class Method Details

.parse(string) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/restify/link.rb', line 33

def parse(string)
  scanner = StringScanner.new(string.strip)

  catch(:invalid) do
    return parse_links(scanner)
  end

  raise ArgumentError.new \
    "Invalid token at #{scanner.pos}: '#{scanner.rest}'"
end