class RichText::Iterator
@api private
Public Class Methods
new(ops)
click to toggle source
# File lib/rich-text/iterator.rb, line 4 def initialize(ops) @ops = ops reset end
Public Instance Methods
each(size = 1) { |nextwhile next?| ... }
click to toggle source
# File lib/rich-text/iterator.rb, line 9 def each(size = 1) return enum_for(:each, size) unless block_given? yield self.next(size) while next? end
next(length = Float::INFINITY)
click to toggle source
# File lib/rich-text/iterator.rb, line 26 def next(length = Float::INFINITY) next_op = @ops[@index] offset = @offset if next_op if length >= next_op.length - offset length = next_op.length - offset @index += 1 @offset = 0 else @offset += length end next_op.slice(offset, length) else return Op.new(:retain, Float::INFINITY) end end
next?()
click to toggle source
# File lib/rich-text/iterator.rb, line 22 def next? peek.length < Float::INFINITY end
peek()
click to toggle source
# File lib/rich-text/iterator.rb, line 14 def peek if op = @ops[@index] op.slice(@offset) else Op.new(:retain, Float::INFINITY) end end
reset()
click to toggle source
# File lib/rich-text/iterator.rb, line 44 def reset @index = 0 @offset = 0 end