Class: RubyDanfe::Document

Inherits:
Prawn::Document
  • Object
show all
Defined in:
lib/ruby_danfe.rb

Instance Method Summary collapse

Instance Method Details

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



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ruby_danfe.rb', line 68

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, :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

#ibarcode(h, w, x, y, info) ⇒ Object



51
52
53
# File 'lib/ruby_danfe.rb', line 51

def ibarcode(h, w, x, y, info)
  Barby::Code128C.new(info).annotate_pdf(self, :x => x.cm, :y => invert(y.cm), :width => w.cm, :height => h.cm) if info != ''
end

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



59
60
61
# File 'lib/ruby_danfe.rb', line 59

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

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



63
64
65
66
# File 'lib/ruby_danfe.rb', line 63

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

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



81
82
83
# File 'lib/ruby_danfe.rb', line 81

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

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



55
56
57
# File 'lib/ruby_danfe.rb', line 55

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

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



91
92
93
94
95
96
97
# File 'lib/ruby_danfe.rb', line 91

def itable(h, w, x, y, data, options = {}, &block)
  self.bounding_box [x.cm, 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



47
48
49
# File 'lib/ruby_danfe.rb', line 47

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

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



85
86
87
88
89
# File 'lib/ruby_danfe.rb', line 85

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