Class: NFe::EntidadeNFe
- Inherits:
-
Object
show all
- Includes:
- ROXML
- Defined in:
- lib/nfe/entidades/entidade_nfe.rb
Direct Known Subclasses
Destinatario, Emitente, EnderecoDestinatario, EnderecoEmitente, IcmsTot, IdentificacaoNFe, Info, InfoProtocolo, NotaFiscal, Transportadora, Veiculo, Volume
Constant Summary
collapse
- @@validations =
[]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.nfe_attr ⇒ Object
22
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 22
alias :nfe_attr :xml_accessor
|
.nfe_attrs ⇒ Object
29
30
31
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 29
def nfe_attrs
roxml_attrs.map(&attr_name)
end
|
.xml_accessor(*attrs) ⇒ Object
24
25
26
27
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 24
def xml_accessor(*attrs)
attr_accessor *attrs
end
|
Instance Method Details
#nfe_attributes ⇒ Object
34
35
36
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 34
def nfe_attributes
self.class.nfe_attrs
end
|
#serialize(params) ⇒ Object
def to_s self.respond_to? :to_nfe ? to_nfe : super end
61
62
63
64
65
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 61
def serialize(params)
params.each do |key, value|
send("#{key}=", value) if respond_to?(key)
end
end
|
#to_nfe ⇒ Object
50
51
52
53
54
55
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 50
def to_nfe
doc = Nokogiri::XML::Document.new
doc.root = to_xml
doc.serialize
end
|
#to_nfe_xml(file) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 38
def to_nfe_xml(file)
entidade = Nokogiri::XML(File.open(file))
doc = Nokogiri::XML::Document.new
doc.root = self.to_xml
puts ">>>>>> #{doc.root.to_s}"
end
|
#to_xml(xml) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 75
def to_xml(xml)
hash = ''
xml.children.each do |i|
hash << "<#{i.name}>#{i.text}</#{i.name}>"
end
hash
end
|
#xml_to_hash(xml) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/nfe/entidades/entidade_nfe.rb', line 67
def xml_to_hash(xml)
hash = {}
xml.children.each do |i|
hash.store(i.name, i.text)
end
hash
end
|