Class: GenSid::CounterNum
Instance Attribute Summary
Attributes inherited from Counter
#current_value, #initial_value, #skip_first_value
Instance Method Summary
collapse
Constructor Details
#initialize(initial_value = 0) ⇒ CounterNum
Returns a new instance of CounterNum.
5
6
7
|
# File 'lib/gen_sid/counter_num.rb', line 5
def initialize(initial_value = 0)
super(initial_value)
end
|
Instance Method Details
#increment ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/gen_sid/counter_num.rb', line 24
def increment
@previous_value = @current_value
if @current_value.nil?
@current_value = @initial_value
else
if @current_value == 9
@current_value = 0
else
@current_value += 1
end
end
end
|
#next_value ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/gen_sid/counter_num.rb', line 13
def next_value
increment
if @skip_first_value
increment
@skip_first_value = false
end
next_val = @current_value
status = @previous_value == 9 ? :rollover : :normal
[next_val,status]
end
|
#value ⇒ Object
9
10
11
|
# File 'lib/gen_sid/counter_num.rb', line 9
def value
@current_value.nil? ? @initial_value : @current_value
end
|