class GenSid::SeqID
Attributes
pattern[R]
total[R]
Public Class Methods
new(pattern = 'A1')
click to toggle source
# File lib/gen_sid/seq_id.rb, line 7 def initialize(pattern = 'A1') @pattern = pattern @reversed_counters = parse_pattern(@pattern).reverse # Set all but first counter to skip first value on increment 1.upto(@reversed_counters.size - 1) do |pos| @reversed_counters[pos].skip_first_value = true end end
Public Instance Methods
next_value()
click to toggle source
# File lib/gen_sid/seq_id.rb, line 16 def next_value # Counters are managed in reverse order - from least-significant (i.e. most rapidly varying) # to most-significant (i.e. least rapidly varying) last_processed = 0 all_next = "" # Stop at first counter that yields a next value without a rollover 0.upto(@reversed_counters.size - 1) do |pos| last_processed = pos counter = @reversed_counters[pos] next_value, status = counter.next_value all_next << next_value.to_s break if (status == :normal) end # Deal with remainder - get current values (last_processed + 1).upto(@reversed_counters.size - 1) do |pos| counter = @reversed_counters[pos] all_next << counter.value.to_s end # Reverse the result all_next.reverse end