Class: Prawn::Repeater

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/repeater.rb

Overview

:nodoc:

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, page_filter, dynamic = false, &block) ⇒ Repeater

Returns a new instance of Repeater.


92
93
94
95
96
97
98
99
100
101
# File 'lib/prawn/repeater.rb', line 92

def initialize(document, page_filter, dynamic = false, &block)
  @document    = document
  @page_filter = page_filter
  @dynamic = dynamic
  @stamp_name  = "prawn_repeater(#{Repeater.count})"
  @document.create_stamp(@stamp_name, &block) unless dynamic
  @block = block if dynamic

  Repeater.count += 1
end

Class Attribute Details

.countObject


85
86
87
# File 'lib/prawn/repeater.rb', line 85

def count
  @count ||= 0
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


90
91
92
# File 'lib/prawn/repeater.rb', line 90

def name
  @name
end

Instance Method Details

#match?(page_number) ⇒ Boolean

Returns:

  • (Boolean)

103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/prawn/repeater.rb', line 103

def match?(page_number)
  case @page_filter
  when :all
    true
  when :odd
    page_number % 2 == 1
  when :even
    page_number % 2 == 0
  when Range, Array
    @page_filter.include?(page_number)
  when Proc
    @page_filter.call(page_number)
  end
end

#run(page_number) ⇒ Object


118
119
120
121
122
123
124
# File 'lib/prawn/repeater.rb', line 118

def run(page_number)
  if !@dynamic
    @document.stamp(@stamp_name) if match?(page_number)
  elsif @block
    @block.arity < 1 ? @document.instance_eval(&@block) : @block[@document]
  end
end