Class: RubyDanfe::Document
- Inherits:
-
Object
- Object
- RubyDanfe::Document
- Defined in:
- lib/ruby_danfe/document.rb
Instance Method Summary collapse
- #box(at, w, h, title = '', info = '', options = {}) ⇒ Object
- #ibarcode(h, w, x, y, info) ⇒ Object
- #ibox(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
- #idate(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #inumeric(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
- #iqrcode(h, w, x, y, info) ⇒ Object
- #irectangle(h, w, x, y) ⇒ Object
- #itable(h, w, x, y, data, options = {}, &block) ⇒ Object
- #ititle(h, w, x, y, title) ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #numeric(at, w, h, title = '', info = '', options = {}) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ruby_danfe/document.rb', line 3 def initialize @document = Prawn::Document.new( :page_size => 'A4', :page_layout => :portrait, :left_margin => 0, :right_margin => 0, :top_margin => 0, :botton_margin => 0 ) @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
16 17 18 |
# File 'lib/ruby_danfe/document.rb', line 16 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
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_danfe/document.rb', line 49 def box(at, w, h, title = '', info = '', = {}) = { :align => :left, :size => 10, :style => nil, :valign => :top, :border => 1 }.merge() self.stroke_rectangle at, w, h if [: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 => [:size], :at => [at[0] + 2, at[1] - (title != '' ? 14 : 4) ], :width => w - 4, :height => h - (title != '' ? 14 : 4), :align => [:align], :style => [:style], :valign => [:valign] end |
#ibarcode(h, w, x, y, info) ⇒ Object
28 29 30 |
# File 'lib/ruby_danfe/document.rb', line 28 def (h, w, x, y, info) 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 = {}) ⇒ Object
40 41 42 |
# File 'lib/ruby_danfe/document.rb', line 40 def ibox(h, w, x, y, title = '', info = '', = {}) box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, end |
#idate(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/ruby_danfe/document.rb', line 44 def idate(h, w, x, y, title = '', info = '', = {}) tt = info.gsub(/T.*/, '').split('-') ibox h, w, x, y, title, "#{tt[2]}/#{tt[1]}/#{tt[0]}", end |
#inumeric(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
62 63 64 |
# File 'lib/ruby_danfe/document.rb', line 62 def inumeric(h, w, x, y, title = '', info = '', = {}) numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, end |
#iqrcode(h, w, x, y, info) ⇒ Object
32 33 34 |
# File 'lib/ruby_danfe/document.rb', line 32 def iqrcode(h, w, x, y, info) Barby::QrCode.new(info, :level => :q).annotate_pdf(self, :x => x.cm, :y => Helper.invert(y.cm), :width => w.cm, :height => h.cm) if info != '' end |
#irectangle(h, w, x, y) ⇒ Object
36 37 38 |
# File 'lib/ruby_danfe/document.rb', line 36 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
72 73 74 75 76 77 78 |
# File 'lib/ruby_danfe/document.rb', line 72 def itable(h, w, x, y, data, = {}, &block) self.bounding_box [x.cm, Helper.invert(y.cm)], :width => w.cm, :height => h.cm do self.table data, do |table| yield(table) end end end |
#ititle(h, w, x, y, title) ⇒ Object
24 25 26 |
# File 'lib/ruby_danfe/document.rb', line 24 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
66 67 68 69 70 |
# File 'lib/ruby_danfe/document.rb', line 66 def numeric(at, w, h, title = '', info = '', = {}) = {:decimals => 2}.merge() info = Helper.numerify(info, [:decimals]) if info != '' box at, w, h, title, info, .merge({:align => :right}) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
20 21 22 |
# File 'lib/ruby_danfe/document.rb', line 20 def respond_to_missing?(method_name, include_private = false) @document.respond_to?(method_name, include_private) || super end |