Class: RichText::Iterator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rich-text/iterator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(ops) ⇒ Iterator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Iterator.



4
5
6
7
# File 'lib/rich-text/iterator.rb', line 4

def initialize(ops)
  @ops = ops
  reset
end

Instance Method Details

#each(size = 1) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
12
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


22
23
24
# File 'lib/rich-text/iterator.rb', line 22

def next?
  peek.length < Float::INFINITY
end

#peekObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
# 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

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
# File 'lib/rich-text/iterator.rb', line 44

def reset
  @index = 0
  @offset = 0
end