Class: Prawn::Core::Chunk

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, params = {}, &action) ⇒ Chunk

Returns a new instance of Chunk.



4
5
6
7
8
# File 'lib/prawn/core/chunk.rb', line 4

def initialize(command, params={}, &action)
   @command      = command 
   @params       = params
   @action       = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



10
11
12
# File 'lib/prawn/core/chunk.rb', line 10

def action
  @action
end

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'lib/prawn/core/chunk.rb', line 10

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/prawn/core/chunk.rb', line 10

def params
  @params
end

Instance Method Details

#[](attr) ⇒ Object



27
28
29
# File 'lib/prawn/core/chunk.rb', line 27

def [](attr)
  @params[attr]
end

#[]=(attr, value) ⇒ Object



31
32
33
# File 'lib/prawn/core/chunk.rb', line 31

def []=(attr, value)
  @params[attr] = value
end

#contentObject



12
13
14
# File 'lib/prawn/core/chunk.rb', line 12

def content
  action.call(self)
end

#to_pdfObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/prawn/core/chunk.rb', line 16

def to_pdf
  case results = content
  when Array
    results.map { |sub_chunk| sub_chunk.to_pdf }.join("\n")
  when Prawn::Core::Chunk
    results.to_pdf
  else
    results
  end
end