Class: Hypostasis::Tuple
- Inherits:
-
Object
- Object
- Hypostasis::Tuple
- Defined in:
- lib/hypostasis/tuple.rb
Class Method Summary collapse
Instance Method Summary collapse
- #append(*extension) ⇒ Object
-
#initialize(*tuple) ⇒ Tuple
constructor
A new instance of Tuple.
- #prepend(*prefix) ⇒ Object
- #to_a ⇒ Object
- #to_range ⇒ Object
- #to_s ⇒ Object
- #trim(count = 0) ⇒ Object
Constructor Details
#initialize(*tuple) ⇒ Tuple
Returns a new instance of Tuple.
2 3 4 5 6 |
# File 'lib/hypostasis/tuple.rb', line 2 def initialize(*tuple) @tuple = tuple.to_a.flatten raise Hypostasis::Errors::InvalidTuple if @tuple.empty? self end |
Class Method Details
.unpack(tuple_string) ⇒ Object
47 48 49 |
# File 'lib/hypostasis/tuple.rb', line 47 def self.unpack(tuple_string) Hypostasis::Tuple.new(FDB::Tuple.unpack(tuple_string)) end |
Instance Method Details
#append(*extension) ⇒ Object
22 23 24 25 26 |
# File 'lib/hypostasis/tuple.rb', line 22 def append(*extension) return self if extension.empty? appended_tuple = @tuple + extension.to_a Hypostasis::Tuple.new(appended_tuple) end |
#prepend(*prefix) ⇒ Object
16 17 18 19 20 |
# File 'lib/hypostasis/tuple.rb', line 16 def prepend(*prefix) return self if prefix.empty? prepended_tuple = prefix.to_a + @tuple Hypostasis::Tuple.new(prepended_tuple) end |
#to_a ⇒ Object
8 9 10 |
# File 'lib/hypostasis/tuple.rb', line 8 def to_a @tuple end |
#to_range ⇒ Object
43 44 45 |
# File 'lib/hypostasis/tuple.rb', line 43 def to_range FDB::Tuple.range(@tuple) end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/hypostasis/tuple.rb', line 12 def to_s @tuple_str ||= FDB::Tuple.pack(@tuple) end |
#trim(count = 0) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hypostasis/tuple.rb', line 28 def trim(count = 0) count = count.to_i raise Hypostasis::Errors::TupleExhausted if count.abs > @tuple.size - 1 trimmed_tuple = @tuple if count > 0 trimmed_tuple.pop(count.abs) Hypostasis::Tuple.new(trimmed_tuple) elsif count < 0 trimmed_tuple.shift(count.abs) Hypostasis::Tuple.new(trimmed_tuple) else self end end |