Class: Nfcom::Builder::DanfeCom
- Inherits:
-
Object
- Object
- Nfcom::Builder::DanfeCom
- Includes:
- Utils::Helpers
- Defined in:
- lib/nfcom/builder/danfe_com.rb
Instance Attribute Summary collapse
-
#logo_path ⇒ Object
readonly
Returns the value of attribute logo_path.
-
#ns ⇒ Object
readonly
Returns the value of attribute ns.
-
#xml_doc ⇒ Object
readonly
Returns the value of attribute xml_doc.
Instance Method Summary collapse
-
#gerar ⇒ Object
—————————- MAIN PUBLIC METHODS —————————-.
- #gerar_arquivo(filepath) ⇒ Object
-
#initialize(xml_autorizado, logo_path: nil) ⇒ DanfeCom
constructor
A new instance of DanfeCom.
Methods included from Utils::Helpers
apenas_numeros, cnpj_valido?, cpf_valido?, formatar_cep, formatar_cnpj, formatar_cpf, formatar_data, formatar_data_hora, formatar_decimal, gerar_id, limitar_texto, remover_acentos, safe_to_date, vazio?
Constructor Details
#initialize(xml_autorizado, logo_path: nil) ⇒ DanfeCom
Returns a new instance of DanfeCom.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nfcom/builder/danfe_com.rb', line 18 def initialize(xml_autorizado, logo_path: nil) raise Errors::XmlError, 'XML não pode ser vazio' if xml_autorizado.nil? || xml_autorizado.strip.empty? @logo_path = logo_path @xml_doc = Nokogiri::XML(xml_autorizado) @ns = 'http://www.portalfiscal.inf.br/nfcom' raise Errors::XmlError, 'XML inválido: não contém elemento NFCom' unless xml_doc.at_xpath('//xmlns:NFCom', 'xmlns' => ns) rescue Nokogiri::XML::SyntaxError => e raise Errors::XmlError, "Erro ao fazer parse do XML: #{e.}" end |
Instance Attribute Details
#logo_path ⇒ Object (readonly)
Returns the value of attribute logo_path.
16 17 18 |
# File 'lib/nfcom/builder/danfe_com.rb', line 16 def logo_path @logo_path end |
#ns ⇒ Object (readonly)
Returns the value of attribute ns.
16 17 18 |
# File 'lib/nfcom/builder/danfe_com.rb', line 16 def ns @ns end |
#xml_doc ⇒ Object (readonly)
Returns the value of attribute xml_doc.
16 17 18 |
# File 'lib/nfcom/builder/danfe_com.rb', line 16 def xml_doc @xml_doc end |
Instance Method Details
#gerar ⇒ Object
MAIN PUBLIC METHODS
34 35 36 37 38 39 |
# File 'lib/nfcom/builder/danfe_com.rb', line 34 def gerar Prawn::Document.new(page_size: 'A4', margin: [5.mm] * 4) do |pdf| setup_fonts(pdf) gerar_conteudo(pdf) end.render end |
#gerar_arquivo(filepath) ⇒ Object
41 42 43 |
# File 'lib/nfcom/builder/danfe_com.rb', line 41 def gerar_arquivo(filepath) File.write(filepath, gerar) end |