class RubyDanfe::Document

Public Class Methods

new(opts = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 3
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

Public Instance Methods

box(at, w, h, title = '', info = '', options = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 52
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
ibarcode(h, w, x, y, info) click to toggle source
# File lib/ruby_danfe/document.rb, line 30
def ibarcode(h, w, x, y, info)
  info = info.gsub(/\D/, '')
  Barby::Code128C.new(info).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm), :width => w.cm, :height => h.cm) if info != ''
end
ibox(h, w, x, y, title = '', info = '', options = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 43
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 = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 47
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 = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 65
def inumeric(h, w, x, y, title = '', info = '', options = {})
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
end
iqrcode(x, y, info, size = nil) click to toggle source
# File lib/ruby_danfe/document.rb, line 35
def iqrcode(x, y, info, size = nil)
  Barby::QrCode.new(info, :level => :q, :size => size).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm)) if info != ''
end
irectangle(h, w, x, y) click to toggle source
# File lib/ruby_danfe/document.rb, line 39
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 = {}) { |table| ... } click to toggle source
# File lib/ruby_danfe/document.rb, line 75
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) click to toggle source
# File lib/ruby_danfe/document.rb, line 26
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
method_missing(method_name, *args, &block) click to toggle source
# File lib/ruby_danfe/document.rb, line 18
def method_missing(method_name, *args, &block)
  @document.send(method_name, *args, &block)
end
numeric(at, w, h, title = '', info = '', options = {}) click to toggle source
# File lib/ruby_danfe/document.rb, line 69
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) click to toggle source
Calls superclass method
# File lib/ruby_danfe/document.rb, line 22
def respond_to_missing?(method_name, include_private = false)
  @document.respond_to?(method_name, include_private) || super
end