Class: FractionalIndexer::OrderKey
- Inherits:
-
Object
- Object
- FractionalIndexer::OrderKey
- Defined in:
- lib/fractional_indexer/order_key.rb
Constant Summary collapse
- INTEGER_BASE_DIGIT =
2
- POSITIVE_SIGNS =
("a".."z").freeze
- NEGATIVE_SIGNS =
("A".."Z").freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #decrement ⇒ Object
- #fractional ⇒ Object
- #increment ⇒ Object
-
#initialize(key) ⇒ OrderKey
constructor
A new instance of OrderKey.
- #integer ⇒ Object
- #maximum_integer? ⇒ Boolean
- #minimum? ⇒ Boolean
- #minimum_integer? ⇒ Boolean
- #present? ⇒ Boolean
Constructor Details
#initialize(key) ⇒ OrderKey
Returns a new instance of OrderKey.
11 12 13 |
# File 'lib/fractional_indexer/order_key.rb', line 11 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/fractional_indexer/order_key.rb', line 9 def key @key end |
Class Method Details
.negative?(key) ⇒ Boolean
15 16 17 |
# File 'lib/fractional_indexer/order_key.rb', line 15 def self.negative?(key) NEGATIVE_SIGNS.cover?(key[0]) end |
.positive?(key) ⇒ Boolean
19 20 21 |
# File 'lib/fractional_indexer/order_key.rb', line 19 def self.positive?(key) POSITIVE_SIGNS.cover?(key[0]) end |
.zero ⇒ Object
23 24 25 |
# File 'lib/fractional_indexer/order_key.rb', line 23 def self.zero "a#{FractionalIndexer.configuration.digits.first}" end |
Instance Method Details
#decrement ⇒ Object
27 28 29 30 31 32 |
# File 'lib/fractional_indexer/order_key.rb', line 27 def decrement new_order_key = Decrementer.execute(self) raise_error("it cannot decrement for min integer") if new_order_key.nil? new_order_key end |
#fractional ⇒ Object
34 35 36 37 38 |
# File 'lib/fractional_indexer/order_key.rb', line 34 def fractional validate! key[integer_digits..] end |
#increment ⇒ Object
40 41 42 43 44 45 |
# File 'lib/fractional_indexer/order_key.rb', line 40 def increment new_order_key = Incrementer.execute(self) raise_error("it cannot increment for max integer") if new_order_key.nil? new_order_key end |
#integer ⇒ Object
47 48 49 50 51 |
# File 'lib/fractional_indexer/order_key.rb', line 47 def integer validate! key[0, integer_digits] end |
#maximum_integer? ⇒ Boolean
53 54 55 |
# File 'lib/fractional_indexer/order_key.rb', line 53 def maximum_integer? integer == maximum_integer end |
#minimum? ⇒ Boolean
61 62 63 |
# File 'lib/fractional_indexer/order_key.rb', line 61 def minimum? minimum_integer? && fractional.empty? end |
#minimum_integer? ⇒ Boolean
57 58 59 |
# File 'lib/fractional_indexer/order_key.rb', line 57 def minimum_integer? integer == minimum_integer end |
#present? ⇒ Boolean
65 66 67 |
# File 'lib/fractional_indexer/order_key.rb', line 65 def present? !(key.nil? || key.empty?) end |