Class: Howrah::Prawn::Commander

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prawn_document, options = {:dry_run => true}) ⇒ Commander

Returns a new instance of Commander.



6
7
8
9
10
# File 'lib/prawn_commander.rb', line 6

def initialize(prawn_document, options = {:dry_run => true})
  @prawn_document = prawn_document
  @prawn_commands = []
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/prawn_commander.rb', line 4

def options
  @options
end

#prawn_commandsObject

Returns the value of attribute prawn_commands.



4
5
6
# File 'lib/prawn_commander.rb', line 4

def prawn_commands
  @prawn_commands
end

#prawn_documentObject

Returns the value of attribute prawn_document.



4
5
6
# File 'lib/prawn_commander.rb', line 4

def prawn_document
  @prawn_document
end

Instance Method Details

#prawn_command(method, *args, &block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/prawn_commander.rb', line 32

def prawn_command(method, *args, &block)
  raise "#{method} is not a valid prawn command on a prawn document" if !valid_prawn_command?(method) 
  add_command(method, args.dup, block != nil)

  # make clone of command to ensure the original is not in any way modified internally by prawn  
  cmd = Marshal.load( Marshal.dump(prawn_commands.last) )        
  prawn_document.send cmd[:method], *cmd[:args] if !options[:dry_run]              
end


28
29
30
# File 'lib/prawn_commander.rb', line 28

def print_raw_prawn_commands
  puts raw_prawn_commands.join("\n")
end

#raw_prawn_commandsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prawn_commander.rb', line 12

def raw_prawn_commands
  raw_commands = []
  prawn_commands.each do |command|
    args = command[:args].size == 1 ? command[:args][0] : command[:args]          
    # arg_str = args
    arg_str = case args 
      when Array
        args.map{|a| a.inspect}.join(',')
      else
        args
    end
    raw_commands << "#{command[:method]} #{arg_str}"
  end
  raw_commands
end