Class: Rypper::Counter
- Inherits:
-
Object
- Object
- Rypper::Counter
- Defined in:
- lib/rypper/counter.rb
Instance Attribute Summary collapse
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
-
#lower ⇒ Object
readonly
Returns the value of attribute lower.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#upper ⇒ Object
readonly
Returns the value of attribute upper.
Instance Method Summary collapse
- #first! ⇒ Object
- #first? ⇒ Boolean
-
#initialize(match, lower, upper, digits = 1, state = nil) ⇒ Counter
constructor
A new instance of Counter.
- #last! ⇒ Object
- #last? ⇒ Boolean
- #next! ⇒ Object
- #prev! ⇒ Object
- #to_s(digits = nil) ⇒ Object
Constructor Details
#initialize(match, lower, upper, digits = 1, state = nil) ⇒ Counter
Returns a new instance of Counter.
11 12 13 14 15 16 17 |
# File 'lib/rypper/counter.rb', line 11 def initialize(match, lower, upper, digits=1, state=nil) @match = match @lower = lower @upper = upper @digits = digits @state = state || @lower end |
Instance Attribute Details
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
8 9 10 |
# File 'lib/rypper/counter.rb', line 8 def digits @digits end |
#lower ⇒ Object (readonly)
Returns the value of attribute lower.
6 7 8 |
# File 'lib/rypper/counter.rb', line 6 def lower @lower end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
5 6 7 |
# File 'lib/rypper/counter.rb', line 5 def match @match end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/rypper/counter.rb', line 9 def state @state end |
#upper ⇒ Object (readonly)
Returns the value of attribute upper.
7 8 9 |
# File 'lib/rypper/counter.rb', line 7 def upper @upper end |
Instance Method Details
#first! ⇒ Object
19 20 21 22 |
# File 'lib/rypper/counter.rb', line 19 def first! @state = @lower self end |
#first? ⇒ Boolean
24 25 26 |
# File 'lib/rypper/counter.rb', line 24 def first? @state == @lower end |
#last! ⇒ Object
46 47 48 49 |
# File 'lib/rypper/counter.rb', line 46 def last! @state = @upper self end |
#last? ⇒ Boolean
51 52 53 |
# File 'lib/rypper/counter.rb', line 51 def last? @state == @upper end |
#next! ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rypper/counter.rb', line 37 def next! if @state < @upper @state += 1 else @state = @lower end self end |
#prev! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/rypper/counter.rb', line 28 def prev! if @state > @lower @state -= 1 else @state = @upper end self end |
#to_s(digits = nil) ⇒ Object
55 56 57 58 |
# File 'lib/rypper/counter.rb', line 55 def to_s(digits=nil) digits ||= self.digits @state.to_s.rjust(digits, '0') end |