class HttpLinkHeader

Constants

DELIMETER
VERSION

Public Class Methods

new(link_header = []) click to toggle source
# File lib/http_link_header.rb, line 7
def initialize(link_header = [])
  link_header = link_header.split(DELIMETER) if link_header.is_a?(String)
  link_header.each { |link_value| add(link_value) }
end

Public Instance Methods

[](uri_reference) click to toggle source
Calls superclass method
# File lib/http_link_header.rb, line 12
def [](uri_reference)
  super(uri_reference.to_s)
end
[]=(uri_reference, link_params) click to toggle source
Calls superclass method
# File lib/http_link_header.rb, line 16
def []=(uri_reference, link_params)
  link_params = nil if link_params && link_params.empty?
  if self[uri_reference]
    self[uri_reference].add(link_params) unless link_params.nil?
  else
    super(uri_reference.to_s, link_params.nil? ? nil : HttpLinkParams.new(link_params))
  end
end
add(link_value) click to toggle source
# File lib/http_link_header.rb, line 25
def add(link_value)
  if link_value_match = link_value.strip.match(/\A<([^>]+)>\s*(;\s*(.*))?\z/)
    uri_reference, link_params = link_value_match.values_at(1, 3)
    self[uri_reference.strip] = link_params ? link_params.strip : nil
  else
    raise ArgumentError, "invalid link-value: #{link_value}"
  end
end
to_a() click to toggle source
# File lib/http_link_header.rb, line 34
def to_a
  map do |uri_reference, link_params|
    link_value = "<#{uri_reference}>"
    link_value << "#{HttpLinkParams::DELIMETER} #{link_params.to_s}" if link_params && !link_params.empty?
    link_value
  end
end
to_s() click to toggle source
# File lib/http_link_header.rb, line 42
def to_s
  to_a.join("#{DELIMETER} ")
end