Class: Fauna::Ref
- Inherits:
-
Object
- Object
- Fauna::Ref
- Defined in:
- lib/fauna/objects.rb
Overview
A Ref.
Reference: FaunaDB Special Types
Instance Attribute Summary collapse
-
#value ⇒ Object
The raw ref string.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns
true
ifother
is a Ref and contains the same value. -
#id ⇒ Object
Removes the class part of the ref, leaving only the id.
-
#initialize(value) ⇒ Ref
constructor
Creates a Ref object.
-
#to_class ⇒ Object
Gets the class part out of the Ref.
-
#to_hash ⇒ Object
Converts the Ref in Hash form.
-
#to_s ⇒ Object
Converts the Ref to a string.
Constructor Details
Instance Attribute Details
#value ⇒ Object
The raw ref string.
8 9 10 |
# File 'lib/fauna/objects.rb', line 8 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true
if other
is a Ref and contains the same value.
55 56 57 58 |
# File 'lib/fauna/objects.rb', line 55 def ==(other) return false unless other.is_a? Ref value == other.value end |
#id ⇒ Object
Removes the class part of the ref, leaving only the id. This is everything after the last /.
38 39 40 41 42 |
# File 'lib/fauna/objects.rb', line 38 def id parts = value.split '/' fail ArgumentError.new 'The Ref does not have an id.' if parts.length == 1 parts.last end |
#to_class ⇒ Object
Gets the class part out of the Ref. This is done by removing ref.id(). So Fauna::Ref.new('a/b/c').to_class
will be Fauna::Ref.new('a/b')
.
26 27 28 29 30 31 32 33 |
# File 'lib/fauna/objects.rb', line 26 def to_class parts = value.split '/' if parts.length == 1 self else Fauna::Ref.new(parts[0...-1].join('/')) end end |
#to_hash ⇒ Object
Converts the Ref in Hash form.
50 51 52 |
# File 'lib/fauna/objects.rb', line 50 def to_hash { :@ref => value } end |
#to_s ⇒ Object
Converts the Ref to a string
45 46 47 |
# File 'lib/fauna/objects.rb', line 45 def to_s value end |