Class: HttpHeaderLink::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, **options) ⇒ Link

Returns a new instance of Link.

Parameters:

  • url (String)
  • options (Hash)

Options Hash (**options):

  • :rel (String)
  • :title (String)
  • :hreflang (String)
  • :media (String)
  • :type (String)


16
17
18
19
# File 'lib/http_header_link/link.rb', line 16

def initialize(url, **options)
  @url = url
  @attributes = options.slice(:rel, :title, :hreflang, :media, :type)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/http_header_link/link.rb', line 7

def attributes
  @attributes
end

#urlString (readonly)

Returns:

  • (String)


6
7
8
# File 'lib/http_header_link/link.rb', line 6

def url
  @url
end

Instance Method Details

#generate(base_url: nil) ⇒ String

Parameters:

  • base_url (String) (defaults to: nil)

Returns:

  • (String)


23
24
25
26
27
28
29
30
# File 'lib/http_header_link/link.rb', line 23

def generate(base_url: nil)
  src = base_url ? URI.join(base_url, url) : url
  str = "<#{src}>"
  attributes.each do |name, value|
    str += %(; #{name}="#{value}")
  end
  str
end

#get_query(name) ⇒ String?

Parameters:

  • name (Symbol)

Returns:

  • (String, nil)


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

def get_query(name)
  query_hash[name.to_s]
end

#hreflangString?

Returns:

  • (String, nil)


44
45
46
# File 'lib/http_header_link/link.rb', line 44

def hreflang
  attributes[:hreflang]
end

#mediaString?

Returns:

  • (String, nil)


54
55
56
# File 'lib/http_header_link/link.rb', line 54

def media
  attributes[:media]
end

#relString?

Returns:

  • (String, nil)


39
40
41
# File 'lib/http_header_link/link.rb', line 39

def rel
  attributes[:rel]
end

#titleString?

Returns:

  • (String, nil)


49
50
51
# File 'lib/http_header_link/link.rb', line 49

def title
  attributes[:title]
end

#typeString?

Returns:

  • (String, nil)


59
60
61
# File 'lib/http_header_link/link.rb', line 59

def type
  attributes[:type]
end