Class: NFe::EntidadeNFe

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/nfe/entidades/entidade_nfe.rb

Constant Summary collapse

@@validations =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.nfe_attrObject



22
# File 'lib/nfe/entidades/entidade_nfe.rb', line 22

alias :nfe_attr :xml_accessor

.nfe_attrsObject



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
	# super(*attrs)
end

Instance Method Details

#nfe_attributesObject



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_nfeObject



50
51
52
53
54
55
# File 'lib/nfe/entidades/entidade_nfe.rb', line 50

def to_nfe
	#depois fazer o teste com REXML
	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 = EntidadeNFe.from_xml(File.read(File.expand_path('example-user.xml', File.dirname(__FILE__))))
#entidade = NFe::EntidadeNFe.from_xml(File.read(File.expand_path(file, File.dirname(__FILE__))))
entidade = Nokogiri::XML(File.open(file))
doc = Nokogiri::XML::Document.new
doc.root = self.to_xml
# open("entidade_nfe.xml", 'w') do |file|
#   file << doc.serialize
# end		
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