Class: LinkHeaders::Link
- Inherits:
-
Object
- Object
- LinkHeaders::Link
- Defined in:
- lib/linkheaders/link.rb
Overview
LinkHeader::Link represnts an HTTP Link Header, an HTML LinkHeader, or a LinkSet Link.
#anchor, #href, and #relation are all guaranteed to return a value. Other methods are dynamically created based on what key/value pairs exist in the link for example, if “‘type’: ‘text/html’” exists in the link description, then the method #type will be available on the Link object.
Instance Attribute Summary collapse
-
#anchor ⇒ String
URL of the Link anchor.
-
#factory ⇒ LinkHeader::LinkFactory
The factory that made the Link.
-
#href ⇒ String
URL of the Link.
-
#linkmethods ⇒ String
The list of instance method names auto-generated by the various key/value pairs in the link header.
-
#relation ⇒ String
What is the relation? (e.g. “cite-as”).
-
#responsepart ⇒ Symbol
:header, :body, or :linkset indicating the place the Link object originated.
Instance Method Summary collapse
-
#initialize(responsepart:, factory:, href:, anchor:, relation:, **kwargs) ⇒ Link
constructor
Create the Link object.
-
#to_html ⇒ String
Create an HTML version of the link.
Constructor Details
#initialize(responsepart:, factory:, href:, anchor:, relation:, **kwargs) ⇒ Link
Create the Link object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/linkheaders/link.rb', line 170 def initialize(responsepart:, factory:, href:, anchor:, relation:, **kwargs) # warn "incoming kw args #{kwargs}" @href = href @anchor = anchor @relation = relation @factory = factory @responsepart = responsepart @linkmethods = Array.new kwargs.each do |k, v| # warn "key #{k} val #{v}" @linkmethods << k define_singleton_method(k.to_sym) { value = instance_variable_get("@#{k}") return value } define_singleton_method "#{k}=".to_sym do |val| instance_variable_set("@#{k}", val) return "@#{k}".to_sym end # warn "methods: #{self.methods - Object.new.methods}" self.send("#{k}=", v) end end |
Instance Attribute Details
#anchor ⇒ String
Returns URL of the Link anchor.
147 148 149 |
# File 'lib/linkheaders/link.rb', line 147 def anchor @anchor end |
#factory ⇒ LinkHeader::LinkFactory
Returns The factory that made the Link.
153 154 155 |
# File 'lib/linkheaders/link.rb', line 153 def factory @factory end |
#href ⇒ String
Returns URL of the Link.
149 150 151 |
# File 'lib/linkheaders/link.rb', line 149 def href @href end |
#linkmethods ⇒ String
Returns the list of instance method names auto-generated by the various key/value pairs in the link header. e.g. “type”.
157 158 159 |
# File 'lib/linkheaders/link.rb', line 157 def linkmethods @linkmethods end |
#relation ⇒ String
Returns What is the relation? (e.g. “cite-as”).
151 152 153 |
# File 'lib/linkheaders/link.rb', line 151 def relation @relation end |
#responsepart ⇒ Symbol
Returns :header, :body, or :linkset indicating the place the Link object originated.
155 156 157 |
# File 'lib/linkheaders/link.rb', line 155 def responsepart @responsepart end |
Instance Method Details
#to_html ⇒ String
Create an HTML version of the link
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/linkheaders/link.rb', line 200 def to_html methods = self.linkmethods href = self.href rel = self.relation anchor = self.anchor properties = [] methods.each do |method| value = self.send(method) properties << [method, value] end properties << ["rel", rel] properties << ["anchor", anchor] LinkHeader::Link.new(href, properties).to_html end |