class HttpLinkHeader::HttpLinkParams

Constants

DELIMETER
RELATION_TYPE_ATTRIBUTES

Public Class Methods

new(link_params) click to toggle source
# File lib/http_link_header/http_link_params.rb, line 37
def initialize(link_params)
  add(link_params)
end

Public Instance Methods

[](attribute) click to toggle source
Calls superclass method
# File lib/http_link_header/http_link_params.rb, line 41
def [](attribute)
  super(attribute.to_s)
end
[]=(attribute, value) click to toggle source
Calls superclass method
# File lib/http_link_header/http_link_params.rb, line 45
def []=(attribute, value)
  if RELATION_TYPE_ATTRIBUTES.include?(attribute.to_s)
    if self[attribute]
      self[attribute].add(value)
    else
      super(attribute.to_s, RelationTypes.new(value))
    end
  else
    super(attribute.to_s, value)
  end
end
add(link_params) click to toggle source
# File lib/http_link_header/http_link_params.rb, line 57
def add(link_params)
  link_params.split(DELIMETER).each do |link_param|
    link_param.strip!
    next if link_param.empty?

    if link_param_match = link_param.match(/\A([\w!#\$&\+\-\.\^`\|~]+\*?)\s*(=\s*(.*))?\z/)
      attribute, value = link_param_match.values_at(1, 3)
      self[attribute.strip] = value ? value.strip : nil
    else
      raise ArgumentError, "invalid link-param: #{link_param}"
    end
  end
end
to_a() click to toggle source
# File lib/http_link_header/http_link_params.rb, line 71
def to_a
  map { |attribute, value| value ? "#{attribute}=#{value.to_s}" : attribute }
end
to_s() click to toggle source
# File lib/http_link_header/http_link_params.rb, line 75
def to_s
  to_a.join("#{DELIMETER} ")
end