Class: Kcl::Types::ExtendedSequenceNumber
- Inherits:
-
Object
- Object
- Kcl::Types::ExtendedSequenceNumber
- Defined in:
- lib/kcl/types/extended_sequence_number.rb
Constant Summary collapse
- TRIM_HORIZON_VALUE =
BigDecimal(-2)
- LATEST_VALUE =
BigDecimal(-1)
- AT_TIMESTAMP_VALUE =
BigDecimal(-3)
Instance Attribute Summary collapse
-
#sequence_number ⇒ Object
readonly
Returns the value of attribute sequence_number.
-
#sub_sequence_number ⇒ Object
readonly
Returns the value of attribute sub_sequence_number.
Class Method Summary collapse
- .digits?(str) ⇒ Boolean
- .digits_or_sentinel?(str) ⇒ Boolean
- .latest ⇒ Kcl::Types::ExtendedSequenceNumber
- .sentinel?(str) ⇒ Boolean
- .shard_end ⇒ Kcl::Types::ExtendedSequenceNumber
- .trim_horizon ⇒ Kcl::Types::ExtendedSequenceNumber
Instance Method Summary collapse
- #equals(extended_sequence_number) ⇒ Boolean
-
#initialize(sequence_number, sub_sequence_number = 0) ⇒ ExtendedSequenceNumber
constructor
A new instance of ExtendedSequenceNumber.
- #value ⇒ BigDecimal
Constructor Details
#initialize(sequence_number, sub_sequence_number = 0) ⇒ ExtendedSequenceNumber
Returns a new instance of ExtendedSequenceNumber.
55 56 57 58 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 55 def initialize(sequence_number, sub_sequence_number = 0) @sequence_number = sequence_number @sub_sequence_number = sub_sequence_number end |
Instance Attribute Details
#sequence_number ⇒ Object (readonly)
Returns the value of attribute sequence_number.
5 6 7 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 5 def sequence_number @sequence_number end |
#sub_sequence_number ⇒ Object (readonly)
Returns the value of attribute sub_sequence_number.
5 6 7 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 5 def sub_sequence_number @sub_sequence_number end |
Class Method Details
.digits?(str) ⇒ Boolean
48 49 50 51 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 48 def self.digits?(str) return false if str.nil? || str.empty? (str =~ /\A[0-9]+\z/) != nil end |
.digits_or_sentinel?(str) ⇒ Boolean
28 29 30 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 28 def self.digits_or_sentinel?(str) digits?(str) || sentinel?(str) end |
.latest ⇒ Kcl::Types::ExtendedSequenceNumber
12 13 14 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 12 def self.latest @_latest ||= self.new(Kcl::Checkpoints::Sentinel::LATEST) end |
.sentinel?(str) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 34 def self.sentinel?(str) case str when Kcl::Checkpoints::Sentinel::TRIM_HORIZON, Kcl::Checkpoints::Sentinel::LATEST, Kcl::Checkpoints::Sentinel::SHARD_END, Kcl::Checkpoints::Sentinel::AT_TIMESTAMP true else false end end |
.shard_end ⇒ Kcl::Types::ExtendedSequenceNumber
17 18 19 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 17 def self.shard_end @_shard_end ||= self.new(Kcl::Checkpoints::Sentinel::SHARD_END) end |
.trim_horizon ⇒ Kcl::Types::ExtendedSequenceNumber
22 23 24 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 22 def self.trim_horizon @_trim_horizon ||= self.new(Kcl::Checkpoints::Sentinel::TRIM_HORIZON) end |
Instance Method Details
#equals(extended_sequence_number) ⇒ Boolean
82 83 84 85 86 87 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 82 def equals(extended_sequence_number) if @sequence_number != extended_sequence_number.sequence_number return false end @sub_sequence_number == extended_sequence_number.sub_sequence_number end |
#value ⇒ BigDecimal
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kcl/types/extended_sequence_number.rb', line 61 def value if self.class.digits?(@sequence_number) return BigDecimal(@sequence_number) end case @sequence_number when Kcl::Checkpoints::Sentinel::LATEST LATEST_VALUE when Kcl::Checkpoints::Sentinel::TRIM_HORIZON TRIM_HORIZON_VALUE when Kcl::Checkpoints::Sentinel::AT_TIMESTAMP AT_TIMESTAMP_VALUE else raise Kcl::Errors::IllegalArgumentError.new( 'Expected a string of digits, TRIM_HORIZON, LATEST or AT_TIMESTAMP but received ' + @sequence_number ) end end |