class StatusEnumerator::Status
Attributes
current[R]
next[R]
prev[R]
Public Class Methods
new(owner, &block)
click to toggle source
# File lib/status_enumerator.rb, line 24 def initialize(owner, &block) raise ArgumentError, '%s is not kind of StatusEnumerator::Status' % owner.inspect unless owner.nil? or owner.kind_of?(StatusEnumerator::Status) raise ArgumentError, 'block not given' if owner.nil? and block.nil? @owner, @block = owner, block || owner.instance_variable_get(:@block) @prev = @current = @next = nil @first_p = @last_p = true end
Public Instance Methods
first?()
click to toggle source
# File lib/status_enumerator.rb, line 19 def first?; !!@first_p end
last?()
click to toggle source
# File lib/status_enumerator.rb, line 20 def last?; !!@last_p end
Private Instance Methods
each_status(enum)
click to toggle source
# File lib/status_enumerator.rb, line 33 def each_status(enum) c = 0 enum.each do |i| put_next i c += 1 if c == 3 n = put_prev set_flags true, false @block.call(self) put_next n @block.call(self) elsif c > 2 @block.call(self) end end.tap do if c > 0 case c when 1 put_next set_flags true, true @block.call(self) when 2 set_flags true, false @block.call(self) put_next set_flags false, true @block.call(self) else put_next set_flags false, true @block.call(self) end end end end
put_next(obj = nil)
click to toggle source
# File lib/status_enumerator.rb, line 69 def put_next(obj = nil) _prev, @prev, @current, @next = @prev, @current, @next, obj @first_p = false _prev end
put_prev(obj = nil)
click to toggle source
# File lib/status_enumerator.rb, line 74 def put_prev(obj = nil) @prev, @current, @next, _next = obj, @prev, @current, @next @last_p = false _next end
set_flags(first, last)
click to toggle source
# File lib/status_enumerator.rb, line 79 def set_flags(first, last) @first_p, @last_p = first, last end