Method: LinkHeaders::Link#initialize

Defined in:
lib/linkheaders/link.rb

#initialize(responsepart:, factory:, href:, anchor:, relation:, **kwargs) ⇒ Link

Create the Link object

Parameters:

  • responsepart (Symbol)

    :header, :body, :linkset

  • factory (LinkHeader::LinkFactory)

    the factory that made the link

  • href (String)

    The URL of the Link

  • anchor (String)

    The URL of the anchor

  • relation (String)

    the Link relation (e.g. “cite-as”)

  • **kwargs (hash)

    The remaining facets of the link (e.g. type => ‘text/html’)



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