Class: Nfse::Pdf::Document

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/danfe/document.rb', line 9

def initialize(opts = {})
  default_opts = {
    :page_size => 'A4',
    :page_layout => :portrait,
    :left_margin => 0,
    :right_margin => 0,
    :top_margin => 0,
    :botton_margin => 0
  }

  @document = Prawn::Document.new(default_opts.merge(opts))

  @document.font "Times-Roman"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



24
25
26
# File 'lib/danfe/document.rb', line 24

def method_missing(method_name, *args, &block)
  @document.send(method_name, *args, &block)
end

Instance Method Details

#box(at, w, h, title = '', info = '', options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/danfe/document.rb', line 51

def box(at, w, h, title = '', info = '', options = {})
  options = {
    :align => :left,
    :size => 10,
    :style => nil,
    :valign => :top,
    :border => 1
  }.merge(options)
  self.stroke_rectangle at, w, h if options[:border] == 1
  self.text_box title, :size => 6, :style => :italic, :at => [at[0] + 2, at[1] - 2], :width => w - 4, :height => 8 if title != ''
  self.text_box info, :size => options[:size], :at => [at[0] + 2, at[1] - (title != '' ? 14 : 4) ], :width => w - 4, :height => h - (title != '' ? 14 : 4), :align => options[:align], :style => options[:style], :valign => options[:valign]
end

#ibox(h, w, x, y, title = '', info = '', options = {}) ⇒ Object



42
43
44
# File 'lib/danfe/document.rb', line 42

def ibox(h, w, x, y, title = '', info = '', options = {})
  box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
end

#idate(h, w, x, y, title = '', info = '', options = {}) ⇒ Object



46
47
48
49
# File 'lib/danfe/document.rb', line 46

def idate(h, w, x, y, title = '', info = '', options = {})
  tt = info.gsub(/T.*/, '').split('-')
  ibox h, w, x, y, title, "#{tt[2]}/#{tt[1]}/#{tt[0]}", options
end

#inumeric(h, w, x, y, title = '', info = '', options = {}) ⇒ Object



64
65
66
# File 'lib/danfe/document.rb', line 64

def inumeric(h, w, x, y, title = '', info = '', options = {})
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
end

#irectangle(h, w, x, y) ⇒ Object



38
39
40
# File 'lib/danfe/document.rb', line 38

def irectangle(h, w, x, y)
  self.stroke_rectangle [x.cm, Helper.invert(y.cm)], w.cm, h.cm
end

#itable(h, w, x, y, data, options = {}, &block) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/danfe/document.rb', line 74

def itable(h, w, x, y, data, options = {}, &block)
  self.bounding_box [x.cm, Helper.invert(y.cm)], :width => w.cm, :height => h.cm do
    self.table data, options do |table|
      yield(table)
    end
  end
end

#ititle(h, w, x, y, title) ⇒ Object



32
33
34
# File 'lib/danfe/document.rb', line 32

def ititle(h, w, x, y, title)
  self.text_box title, :size => 10, :at => [x.cm, Helper.invert(y.cm) - 2], :width => w.cm, :height => h.cm, :style => :bold
end

#numeric(at, w, h, title = '', info = '', options = {}) ⇒ Object



68
69
70
71
72
# File 'lib/danfe/document.rb', line 68

def numeric(at, w, h, title = '', info = '', options = {})
  options = {:decimals => 2}.merge(options)
  info = Helper.numerify(info, options[:decimals]) if info != ''
  box at, w, h, title, info, options.merge({:align => :right})
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(method_name, include_private = false)
  @document.respond_to?(method_name, include_private) || super
end