Class: Transit::Link
- Inherits:
-
Object
- Object
- Transit::Link
- Defined in:
- lib/transit/transit_types.rb
Overview
Represents a transit hypermedia link extension type.
Constant Summary collapse
- KEYS =
["href", "rel", "name", "render", "prompt"]
- RENDER_VALUES =
["link", "image"]
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
- #href ⇒ Object
-
#initialize(*args) ⇒ Link
constructor
A new instance of Link.
- #name ⇒ Object
- #prompt ⇒ Object
- #rel ⇒ Object
- #render ⇒ Object
- #to_h ⇒ Object
Constructor Details
#Link.new(hash) ⇒ Link #Link.new(href, rel, name, render, prompt) ⇒ Link
Returns a new instance of Link.
189 190 191 192 193 194 195 196 197 |
# File 'lib/transit/transit_types.rb', line 189 def initialize(*args) @values = if args[0].is_a?(Hash) reconcile_values(args[0]) elsif args.length >= 2 && (args[0].is_a?(Addressable::URI) || args[0].is_a?(String)) reconcile_values(Hash[KEYS.zip(args)]) else raise ArgumentError, "The first argument to Link.new can be a URI, String or a Hash. When the first argument is a URI or String, the second argument, rel, must present." end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
209 210 211 |
# File 'lib/transit/transit_types.rb', line 209 def ==(other) other.is_a?(Link) && other.to_h == to_h end |
#hash ⇒ Object
214 215 216 |
# File 'lib/transit/transit_types.rb', line 214 def hash @values.hash end |
#href ⇒ Object
199 |
# File 'lib/transit/transit_types.rb', line 199 def href; @href ||= @values["href"] end |
#name ⇒ Object
201 |
# File 'lib/transit/transit_types.rb', line 201 def name; @name ||= @values["name"] end |
#prompt ⇒ Object
203 |
# File 'lib/transit/transit_types.rb', line 203 def prompt; @prompt ||= @values["prompt"] end |
#rel ⇒ Object
200 |
# File 'lib/transit/transit_types.rb', line 200 def rel; @rel ||= @values["rel"] end |
#render ⇒ Object
202 |
# File 'lib/transit/transit_types.rb', line 202 def render; @render ||= @values["render"] end |
#to_h ⇒ Object
205 206 207 |
# File 'lib/transit/transit_types.rb', line 205 def to_h @values end |