Class: BrDanfe::DanfeLib::NfeLib::Document
- Inherits:
-
Object
- Object
- BrDanfe::DanfeLib::NfeLib::Document
- Defined in:
- lib/br_danfe/danfe_lib/nfe_lib/document.rb
Instance Method Summary collapse
- #i18n_lbox(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
- #ibarcode(h, w, x, y, info) ⇒ Object
- #ibox(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #inumeric(h, w, x, y, i18n = '', data = '', options = {}) ⇒ Object
- #ititle(h, w, x, y, i18n) ⇒ Object
- #lbox(h, w, x, y, xml, xpath, options = {}) ⇒ Object
- #lcnpj(h, w, x, y, xml, xpath, options = {}) ⇒ Object
- #ldate(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
- #lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {}) ⇒ Object
- #lnumeric(h, w, x, y, xml, xpath, options = {}) ⇒ Object
- #ltime(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 5 def initialize @document = BrDanfe::DocumentBuilder.build( page_size: 'A4', page_layout: :portrait, left_margin: 0, right_margin: 0, top_margin: 0, botton_margin: 0 ) @document.font 'tinos' @document.line_width = 0.3 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 20 def method_missing(method_name, *args, &block) if @document.respond_to? method_name @document.send method_name, *args, &block else super end end |
Instance Method Details
#i18n_lbox(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
104 105 106 107 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 104 def i18n_lbox(h, w, x, y, i18n = '', info = '', = {}) label = i18n != '' ? I18n.t("danfe.#{i18n}") : '' ibox h, w, x, y, label, info, end |
#ibarcode(h, w, x, y, info) ⇒ Object
39 40 41 42 43 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 39 def (h, w, x, y, info) if info != '' Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm) end end |
#ibox(h, w, x, y, title = '', info = '', options = {}) ⇒ Object
45 46 47 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 45 def ibox(h, w, x, y, title = '', info = '', = {}) box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, end |
#inumeric(h, w, x, y, i18n = '', data = '', options = {}) ⇒ Object
99 100 101 102 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 99 def inumeric(h, w, x, y, i18n = '', data = '', = {}) label = i18n != '' ? I18n.t("danfe.#{i18n}") : '' numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, end |
#ititle(h, w, x, y, i18n) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 32 def ititle(h, w, x, y, i18n) title = '' title = I18n.t("danfe.#{i18n}") if i18n != '' text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold end |
#lbox(h, w, x, y, xml, xpath, options = {}) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 49 def lbox(h, w, x, y, xml, xpath, = {}) i18n = xpath.tr('/', '.') label = I18n.t("danfe.#{i18n}") data = xml[xpath] ibox(h, w, x, y, label, data, ) end |
#lcnpj(h, w, x, y, xml, xpath, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 67 def lcnpj(h, w, x, y, xml, xpath, = {}) i18n = xpath.tr('/', '.') cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath]) data = if cnpj.valid? cnpj.formatted else '' end i18n_lbox(h, w, x, y, i18n, data, ) end |
#ldate(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 57 def ldate(h, w, x, y, i18n = '', info = '', = {}) data = Helper.format_date(info) i18n_lbox(h, w, x, y, i18n, data, ) end |
#lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 80 def lie(h, w, x, y, xml, xpath_uf, xpath_ie, = {}) i18n = xpath_ie.tr('/', '.') data = '' if BrDanfe::Uf.include?(xml[xpath_uf]) ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie]) data = ie.formatted if ie.valid? end i18n_lbox(h, w, x, y, i18n, data, ) end |
#lnumeric(h, w, x, y, xml, xpath, options = {}) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 92 def lnumeric(h, w, x, y, xml, xpath, = {}) i18n = xpath.tr('/', '.') data = xml[xpath] inumeric(h, w, x, y, i18n, data, ) end |
#ltime(h, w, x, y, i18n = '', info = '', options = {}) ⇒ Object
62 63 64 65 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 62 def ltime(h, w, x, y, i18n = '', info = '', = {}) data = Helper.format_time(info) i18n_lbox(h, w, x, y, i18n, data, ) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
28 29 30 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/document.rb', line 28 def respond_to_missing?(method_name, include_private = false) @document.respond_to?(method_name, include_private) || super end |