Class: HttpHeaders::Link::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href, index:, parameters:) ⇒ Entry

Returns a new instance of Entry.



19
20
21
22
23
24
25
# File 'lib/http_headers/link.rb', line 19

def initialize(href, index:, parameters:)
  self.href = href[1...-1]
  self.parameters = parameters
  self.index = index

  freeze
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



27
28
29
# File 'lib/http_headers/link.rb', line 27

def href
  @href
end

#indexObject

Returns the value of attribute index.



27
28
29
# File 'lib/http_headers/link.rb', line 27

def index
  @index
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
# File 'lib/http_headers/link.rb', line 34

def <=>(other)
  index <=> other.index
end

#[](parameter) ⇒ Object



38
39
40
# File 'lib/http_headers/link.rb', line 38

def [](parameter)
  parameters.fetch(String(parameter).to_sym)
end

#relObject

noinspection RubyInstanceMethodNamingConvention



30
31
32
# File 'lib/http_headers/link.rb', line 30

def rel
  parameters.fetch(:rel) { nil }
end

#to_headerObject



42
43
44
# File 'lib/http_headers/link.rb', line 42

def to_header
  to_s
end

#to_sObject



46
47
48
# File 'lib/http_headers/link.rb', line 46

def to_s
  ["<#{href}>"].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ')
end