Class: HttpHeaderLink::Link
- Inherits:
-
Object
- Object
- HttpHeaderLink::Link
- Defined in:
- lib/http_header_link/link.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
- #url ⇒ String readonly
Instance Method Summary collapse
- #generate(base_url: nil) ⇒ String
- #get_query(name) ⇒ String?
- #hreflang ⇒ String?
-
#initialize(url, **options) ⇒ Link
constructor
A new instance of Link.
- #media ⇒ String?
- #rel ⇒ String?
- #title ⇒ String?
- #type ⇒ String?
Constructor Details
#initialize(url, **options) ⇒ Link
Returns a new instance of Link.
16 17 18 19 |
# File 'lib/http_header_link/link.rb', line 16 def initialize(url, **) @url = url @attributes = .slice(:rel, :title, :hreflang, :media, :type) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/http_header_link/link.rb', line 7 def attributes @attributes end |
#url ⇒ String (readonly)
6 7 8 |
# File 'lib/http_header_link/link.rb', line 6 def url @url end |
Instance Method Details
#generate(base_url: nil) ⇒ 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?
34 35 36 |
# File 'lib/http_header_link/link.rb', line 34 def get_query(name) query_hash[name.to_s] end |
#hreflang ⇒ String?
44 45 46 |
# File 'lib/http_header_link/link.rb', line 44 def hreflang attributes[:hreflang] end |
#media ⇒ String?
54 55 56 |
# File 'lib/http_header_link/link.rb', line 54 def media attributes[:media] end |
#rel ⇒ String?
39 40 41 |
# File 'lib/http_header_link/link.rb', line 39 def rel attributes[:rel] end |
#title ⇒ String?
49 50 51 |
# File 'lib/http_header_link/link.rb', line 49 def title attributes[:title] end |
#type ⇒ String?
59 60 61 |
# File 'lib/http_header_link/link.rb', line 59 def type attributes[:type] end |