Class: Sawyer::Relation::Map
- Inherits:
-
Object
- Object
- Sawyer::Relation::Map
- Defined in:
- lib/sawyer/relation.rb
Instance Method Summary collapse
-
#<<(rel) ⇒ Object
Adds a Relation to the map.
-
#[](key) ⇒ Object
Gets the raw Relation by its name.
-
#initialize ⇒ Map
constructor
Tracks the available next actions for a resource, and issues requests for them.
- #inspect ⇒ Object
-
#keys ⇒ Object
Gets a list of the Relation names.
-
#size ⇒ Object
Gets the number of mapped Relations.
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize ⇒ Map
Tracks the available next actions for a resource, and issues requests for them.
6 7 8 |
# File 'lib/sawyer/relation.rb', line 6 def initialize @map = {} end |
Instance Method Details
#<<(rel) ⇒ Object
Adds a Relation to the map.
rel - A Relation.
Returns nothing.
15 16 17 |
# File 'lib/sawyer/relation.rb', line 15 def <<(rel) @map[rel.name] = rel if rel end |
#[](key) ⇒ Object
Gets the raw Relation by its name.
key - The Symbol name of the Relation.
Returns a Relation.
24 25 26 |
# File 'lib/sawyer/relation.rb', line 24 def [](key) @map[key.to_sym] end |
#inspect ⇒ Object
50 51 52 53 |
# File 'lib/sawyer/relation.rb', line 50 def inspect hash = to_hash hash.respond_to?(:pretty_inspect) ? hash.pretty_inspect : hash.inspect end |
#keys ⇒ Object
Gets a list of the Relation names.
Returns an Array of Symbols in no specific order.
38 39 40 |
# File 'lib/sawyer/relation.rb', line 38 def keys @map.keys end |
#size ⇒ Object
Gets the number of mapped Relations.
Returns an Integer.
31 32 33 |
# File 'lib/sawyer/relation.rb', line 31 def size @map.size end |
#to_hash ⇒ Object Also known as: to_h
42 43 44 45 46 47 |
# File 'lib/sawyer/relation.rb', line 42 def to_hash pairs = @map.map do |k, v| [(k.to_s + "_url").to_sym, v.href] end Hash[pairs] end |