class Roar::Hypermedia::Hyperlink

An abstract hypermedia link with arbitrary attributes.

Public Class Methods

new(attrs={}) click to toggle source
# File lib/roar/hypermedia.rb, line 126
def initialize(attrs={})
  @attrs = attributes!(attrs)
end

Public Instance Methods

merge!(attrs) click to toggle source

Only way to write to Hyperlink after creation.

# File lib/roar/hypermedia.rb, line 136
def merge!(attrs)
  @attrs.merge!(attributes!(attrs))
end
replace(attrs) click to toggle source
# File lib/roar/hypermedia.rb, line 130
def replace(attrs) # makes it work with Hash::Hash.
  @attrs = attributes!(attrs)
  self
end

Private Instance Methods

attributes!(attrs) click to toggle source

Converts keys to strings.

# File lib/roar/hypermedia.rb, line 146
def attributes!(attrs)
  attrs.inject({}) { |hsh, kv| hsh[kv.first.to_s] = kv.last; hsh }.tap do |hsh|
    hsh["rel"] = hsh["rel"].to_s if hsh["rel"]
  end
end
method_missing(name) click to toggle source
# File lib/roar/hypermedia.rb, line 141
def method_missing(name)
  @attrs[name.to_s]
end