class Halibut::Core::Link
This class represents a HAL Link
object.
spec spec spec.
Attributes
The URI associated with this link.
Public Class Methods
Returns an instance of a HAL Link
object
# link with no options link = Link.new('http://homeopathy.org') # link with name and type options link = Link.new('http://homeopathy.org', name: 'Homeopath' , type: 'text/html')
If you pass an options that is not one of the reserved link properties as defined by the spec, they are dropped. It should possibly raise an error, hafta think about it.
@param [String] href URI or URI Template @param [Hash] opts Options: type, name, profile, title, hreflang
@return [Halibut::Core::Link] HAL Link
object
# File lib/halibut/core/link.rb, line 31 def initialize(href, opts={}) @href = href @options = Options.new opts end
Public Instance Methods
Generic comparison method.
Two objects are the same if they have the same href and the same options.
link_one = Link.new('/link', name: 'One', type: 'text/html') link_two = Link.new('/link', name: 'One', type: 'text/html') link_one == link_two # => true
@param [Link] other Link
object to compare to @return [true,false] return of the comparison of the two objects
# File lib/halibut/core/link.rb, line 58 def ==(other) @href == other.href && @options == other.options end
Simply returns a hash of the href and the options that are not empty.
link = Link.new('/links', name: 'Links') link.to_hash # => { "href" => "/links", "name" => "links" }
@return [Hash] hash from Link
Object
# File lib/halibut/core/link.rb, line 43 def to_hash { 'href' => href }.merge @options end