nfe_reader 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/nfe_reader.rb +4 -4
- data/lib/nfe_reader/address.rb +38 -0
- data/lib/nfe_reader/authorization.rb +8 -10
- data/lib/nfe_reader/billing.rb +21 -0
- data/lib/nfe_reader/billing/duplicate.rb +14 -0
- data/lib/nfe_reader/carrier.rb +12 -14
- data/lib/nfe_reader/customer.rb +15 -57
- data/lib/nfe_reader/delivery.rb +16 -18
- data/lib/nfe_reader/document.rb +63 -65
- data/lib/nfe_reader/export.rb +8 -10
- data/lib/nfe_reader/fiscal.rb +29 -31
- data/lib/nfe_reader/header.rb +114 -123
- data/lib/nfe_reader/helpers/attribute_helper.rb +24 -0
- data/lib/nfe_reader/helpers/creator_helper.rb +40 -0
- data/lib/{helpers → nfe_reader/helpers}/nokogiri_hash.rb +2 -0
- data/lib/nfe_reader/information.rb +17 -19
- data/lib/nfe_reader/nfe.rb +78 -87
- data/lib/nfe_reader/person.rb +53 -0
- data/lib/nfe_reader/product.rb +69 -67
- data/lib/nfe_reader/product/armament.rb +18 -20
- data/lib/nfe_reader/product/cane.rb +22 -24
- data/lib/nfe_reader/product/exportation.rb +15 -17
- data/lib/nfe_reader/product/fuel.rb +13 -15
- data/lib/nfe_reader/product/importation.rb +42 -44
- data/lib/nfe_reader/product/medicament.rb +15 -17
- data/lib/nfe_reader/product/vehicle.rb +113 -115
- data/lib/nfe_reader/provider.rb +10 -40
- data/lib/nfe_reader/purchase.rb +9 -12
- data/lib/nfe_reader/removal.rb +17 -19
- data/lib/nfe_reader/taxation/cofins.rb +41 -41
- data/lib/nfe_reader/taxation/cofins_st.rb +15 -17
- data/lib/nfe_reader/taxation/icms.rb +80 -81
- data/lib/nfe_reader/taxation/importation_tax.rb +14 -16
- data/lib/nfe_reader/taxation/ipi.rb +35 -37
- data/lib/nfe_reader/taxation/issqn.rb +17 -19
- data/lib/nfe_reader/taxation/pis.rb +41 -41
- data/lib/nfe_reader/taxation/pis_st.rb +16 -18
- data/lib/nfe_reader/total.rb +71 -71
- data/lib/nfe_reader/transport.rb +76 -89
- data/lib/nfe_reader/version.rb +2 -4
- data/nfe-reader.gemspec +2 -1
- data/test/nfe_reader/address_test.rb +75 -0
- data/test/nfe_reader/authorization_test.rb +2 -2
- data/test/nfe_reader/{collection → billing}/duplicate_test.rb +2 -2
- data/test/nfe_reader/{collection_test.rb → billing_test.rb} +13 -13
- data/test/nfe_reader/cane_test.rb +2 -2
- data/test/nfe_reader/carrier_test.rb +4 -4
- data/test/nfe_reader/customer_test.rb +6 -101
- data/test/nfe_reader/delivery_test.rb +2 -2
- data/test/nfe_reader/document_test.rb +2 -2
- data/test/nfe_reader/export_test.rb +2 -2
- data/test/nfe_reader/fiscal_test.rb +2 -2
- data/test/nfe_reader/header_test.rb +2 -2
- data/test/{helpers → nfe_reader/helpers}/attributte_helper_test.rb +3 -3
- data/test/{helpers → nfe_reader/helpers}/creator_helper_test.rb +3 -3
- data/test/{helpers → nfe_reader/helpers}/nokogiri_test.rb +1 -1
- data/test/nfe_reader/information_test.rb +2 -2
- data/test/nfe_reader/nfe_test.rb +13 -13
- data/test/nfe_reader/person_test.rb +60 -0
- data/test/nfe_reader/product/armament_test.rb +2 -2
- data/test/nfe_reader/product/exportation_test.rb +2 -2
- data/test/nfe_reader/product/fuel_test.rb +2 -2
- data/test/nfe_reader/product/importation_test.rb +2 -2
- data/test/nfe_reader/product/medicament_test.rb +2 -2
- data/test/nfe_reader/product/vehicle_test.rb +2 -2
- data/test/nfe_reader/product_test.rb +2 -2
- data/test/nfe_reader/provider_test.rb +5 -118
- data/test/nfe_reader/purchase_test.rb +2 -2
- data/test/nfe_reader/removal_test.rb +2 -2
- data/test/nfe_reader/taxation/cofins_st_test.rb +2 -2
- data/test/nfe_reader/taxation/cofins_test.rb +2 -2
- data/test/nfe_reader/taxation/icms_test.rb +2 -2
- data/test/nfe_reader/taxation/importation_tax_test.rb +2 -2
- data/test/nfe_reader/taxation/ipi_test.rb +2 -2
- data/test/nfe_reader/taxation/issqn_test.rb +2 -2
- data/test/nfe_reader/taxation/pis_st_test.rb +2 -2
- data/test/nfe_reader/taxation/pis_test.rb +2 -2
- data/test/nfe_reader/total_test.rb +2 -2
- data/test/nfe_reader/transport_test.rb +3 -3
- metadata +37 -17
- data/lib/helpers/attribute_helper.rb +0 -18
- data/lib/helpers/creator_helper.rb +0 -32
- data/lib/nfe_reader/collection.rb +0 -38
- data/lib/nfe_reader/collection/duplicate.rb +0 -16
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path("
|
1
|
+
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe AttributeHelper do
|
3
|
+
describe NfeReader::AttributeHelper do
|
4
4
|
class AttributeTest
|
5
|
-
include AttributeHelper
|
5
|
+
include NfeReader::AttributeHelper
|
6
6
|
attr_accessor :first_name, :last_name
|
7
7
|
|
8
8
|
def initialize( attrs= {})
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path("
|
1
|
+
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe CreatorHelper do
|
3
|
+
describe NfeReader::CreatorHelper do
|
4
4
|
class CreatorTest < Struct.new(:name)
|
5
|
-
include CreatorHelper
|
5
|
+
include NfeReader::CreatorHelper
|
6
6
|
end
|
7
7
|
|
8
8
|
class ResourceTest < Struct.new(:name)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Information do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
infAdic: {
|
@@ -25,7 +25,7 @@ describe Nfe::Reader::Information do
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
let(:information) {
|
28
|
+
let(:information) { NfeReader::Information.new(nfe_hash[:infAdic]) }
|
29
29
|
|
30
30
|
it '#information' do
|
31
31
|
information.information.must_equal 'Information'
|
data/test/nfe_reader/nfe_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
4
|
-
let (:nfe) {
|
3
|
+
describe NfeReader::Nfe do
|
4
|
+
let (:nfe) { NfeReader::Nfe.new(File.open(file)) }
|
5
5
|
|
6
6
|
describe 'many products' do
|
7
7
|
let(:file) { File.open(File.expand_path("../../files/sample-nfe.xml", __FILE__))}
|
@@ -19,23 +19,23 @@ describe Nfe::Reader::Nfe do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it '#customer' do
|
22
|
-
nfe.customer.must_be_instance_of
|
22
|
+
nfe.customer.must_be_instance_of NfeReader::Customer
|
23
23
|
end
|
24
24
|
|
25
25
|
it '#information' do
|
26
|
-
nfe.information.must_be_instance_of
|
26
|
+
nfe.information.must_be_instance_of NfeReader::Information
|
27
27
|
end
|
28
28
|
|
29
29
|
it '#header' do
|
30
|
-
nfe.header.must_be_instance_of
|
30
|
+
nfe.header.must_be_instance_of NfeReader::Header
|
31
31
|
end
|
32
32
|
|
33
33
|
it '#provider' do
|
34
|
-
nfe.provider.must_be_instance_of
|
34
|
+
nfe.provider.must_be_instance_of NfeReader::Provider
|
35
35
|
end
|
36
36
|
|
37
37
|
it '#customer' do
|
38
|
-
nfe.customer.must_be_instance_of
|
38
|
+
nfe.customer.must_be_instance_of NfeReader::Customer
|
39
39
|
end
|
40
40
|
|
41
41
|
it '#products' do
|
@@ -43,15 +43,15 @@ describe Nfe::Reader::Nfe do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it '#products' do
|
46
|
-
nfe.products.first.must_be_instance_of
|
46
|
+
nfe.products.first.must_be_instance_of NfeReader::Product
|
47
47
|
end
|
48
48
|
|
49
|
-
it '#
|
50
|
-
nfe.
|
49
|
+
it '#billing' do
|
50
|
+
nfe.billing.must_be_instance_of NfeReader::Billing
|
51
51
|
end
|
52
52
|
|
53
53
|
it '#transport' do
|
54
|
-
nfe.transport.must_be_instance_of
|
54
|
+
nfe.transport.must_be_instance_of NfeReader::Transport
|
55
55
|
end
|
56
56
|
|
57
57
|
it '#purchase' do
|
@@ -107,7 +107,7 @@ describe Nfe::Reader::Nfe do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it '#total' do
|
110
|
-
nfe.total.must_be_instance_of
|
110
|
+
nfe.total.must_be_instance_of NfeReader::Total
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -119,7 +119,7 @@ describe Nfe::Reader::Nfe do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it '#products' do
|
122
|
-
nfe.products.first.must_be_instance_of
|
122
|
+
nfe.products.first.must_be_instance_of NfeReader::Product
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
describe NfeReader::Person do
|
4
|
+
def cte_hash
|
5
|
+
{
|
6
|
+
CNPJ: '58571647000153',
|
7
|
+
CPF: '63123256952',
|
8
|
+
IE: '1029384756',
|
9
|
+
xNome: 'Person',
|
10
|
+
xFant: 'Fantasy',
|
11
|
+
fone: '55 5555-5555',
|
12
|
+
email: 'email@localhost',
|
13
|
+
UF: 'ST',
|
14
|
+
RNTRC: '123812083',
|
15
|
+
tpProp: '1'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:person) { NfeReader::Person.new(cte_hash) }
|
20
|
+
|
21
|
+
it '#cnpj' do
|
22
|
+
person.cnpj.must_equal cte_hash[:CNPJ]
|
23
|
+
end
|
24
|
+
|
25
|
+
it '#cpf' do
|
26
|
+
person.cpf.must_equal cte_hash[:CPF]
|
27
|
+
end
|
28
|
+
|
29
|
+
it '#state_registration' do
|
30
|
+
person.state_registration.must_equal cte_hash[:IE]
|
31
|
+
end
|
32
|
+
|
33
|
+
it '#name' do
|
34
|
+
person.name.must_equal cte_hash[:xNome]
|
35
|
+
end
|
36
|
+
|
37
|
+
it '#fantasy' do
|
38
|
+
person.fantasy.must_equal cte_hash[:xFant]
|
39
|
+
end
|
40
|
+
|
41
|
+
it '#phone' do
|
42
|
+
person.phone.must_equal cte_hash[:fone]
|
43
|
+
end
|
44
|
+
|
45
|
+
it '#email' do
|
46
|
+
person.email.must_equal cte_hash[:email]
|
47
|
+
end
|
48
|
+
|
49
|
+
it '#state' do
|
50
|
+
person.state.must_equal cte_hash[:UF]
|
51
|
+
end
|
52
|
+
|
53
|
+
it '#rntrc' do
|
54
|
+
person.rntrc.must_equal cte_hash[:RNTRC]
|
55
|
+
end
|
56
|
+
|
57
|
+
it '#owner_kind' do
|
58
|
+
person.owner_kind.must_equal cte_hash[:tpProp]
|
59
|
+
end
|
60
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Armament do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
armament: {
|
@@ -12,7 +12,7 @@ describe Nfe::Reader::Armament do
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:armament) {
|
15
|
+
let(:armament) { NfeReader::Armament.new(nfe_hash[:armament]) }
|
16
16
|
|
17
17
|
it '#kind' do
|
18
18
|
armament.kind.must_equal '1'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Exportation do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
detExport: {
|
@@ -14,7 +14,7 @@ describe Nfe::Reader::Exportation do
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:exportation) {
|
17
|
+
let(:exportation) { NfeReader::Exportation.new(nfe_hash[:detExport]) }
|
18
18
|
|
19
19
|
it '#drawnback' do
|
20
20
|
exportation.drawnback.must_equal '1'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Fuel do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
fuel: {
|
@@ -16,7 +16,7 @@ describe Nfe::Reader::Fuel do
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
let(:fuel) {
|
19
|
+
let(:fuel) { NfeReader::Fuel.new(nfe_hash[:fuel]) }
|
20
20
|
|
21
21
|
it '#anp' do
|
22
22
|
fuel.anp.must_equal '10613541'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Importation do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
importation: {
|
@@ -25,7 +25,7 @@ describe Nfe::Reader::Importation do
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
let(:importation) {
|
28
|
+
let(:importation) { NfeReader::Importation.new(nfe_hash[:importation]) }
|
29
29
|
|
30
30
|
it '#afrmm' do
|
31
31
|
importation.afrmm.must_equal '100.00'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Medicament do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
medicament: {
|
@@ -13,7 +13,7 @@ describe Nfe::Reader::Medicament do
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:medicament) {
|
16
|
+
let(:medicament) { NfeReader::Medicament.new(nfe_hash[:medicament]) }
|
17
17
|
|
18
18
|
it '#lot_number' do
|
19
19
|
medicament.lot_number.must_equal '123980'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Vehicle do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
vehicle: {
|
@@ -33,7 +33,7 @@ describe Nfe::Reader::Vehicle do
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
-
let(:vehicle) {
|
36
|
+
let(:vehicle) { NfeReader::Vehicle.new(nfe_hash[:vehicle]) }
|
37
37
|
|
38
38
|
it '#operation' do
|
39
39
|
vehicle.operation.must_equal '1'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Product do
|
4
4
|
def product_hash
|
5
5
|
{
|
6
6
|
product: {
|
@@ -33,7 +33,7 @@ describe Nfe::Reader::Product do
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
-
let(:product) {
|
36
|
+
let(:product) { NfeReader::Product.new(product_hash[:product]) }
|
37
37
|
|
38
38
|
it '#demand_item' do
|
39
39
|
product.demand_item.must_equal '23'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Provider do
|
4
4
|
def provider_hash
|
5
5
|
{
|
6
6
|
emit: {
|
@@ -30,126 +30,13 @@ describe Nfe::Reader::Provider do
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
let(:provider) { Nfe::Reader::Provider.new(provider_hash[:emit]) }
|
33
|
+
let(:provider) { NfeReader::Provider.new(provider_hash[:emit]) }
|
35
34
|
|
36
|
-
it '#
|
37
|
-
provider.
|
38
|
-
end
|
39
|
-
|
40
|
-
it '#cpf' do
|
41
|
-
provider.cpf.must_equal '64046757655'
|
42
|
-
end
|
43
|
-
|
44
|
-
it '#name' do
|
45
|
-
provider.name.must_equal 'Provider'
|
46
|
-
end
|
47
|
-
|
48
|
-
it '#fantasia' do
|
49
|
-
provider.fantasy.must_equal 'Provider'
|
50
|
-
end
|
51
|
-
|
52
|
-
it '#state_registration' do
|
53
|
-
provider.state_registration.must_equal '15786913'
|
54
|
-
end
|
55
|
-
|
56
|
-
it '#state_registration_st' do
|
57
|
-
provider.state_registration_st.must_equal '975940113'
|
58
|
-
end
|
59
|
-
|
60
|
-
it '#city_registration' do
|
61
|
-
provider.city_registration.must_equal '3856749'
|
62
|
-
end
|
63
|
-
|
64
|
-
it '#regime' do
|
65
|
-
provider.regime.must_equal '1'
|
66
|
-
end
|
67
|
-
|
68
|
-
it '#cnae' do
|
69
|
-
provider.cnae.must_equal '123456'
|
70
|
-
end
|
71
|
-
|
72
|
-
it '#phone' do
|
73
|
-
provider.phone.must_equal '55 5555-5555'
|
74
|
-
end
|
75
|
-
|
76
|
-
it '#number' do
|
77
|
-
provider.number.must_equal '123'
|
78
|
-
end
|
79
|
-
|
80
|
-
it '#complement' do
|
81
|
-
provider.complement.must_equal ''
|
35
|
+
it '#person' do
|
36
|
+
provider.person.must_be_instance_of NfeReader::Person
|
82
37
|
end
|
83
38
|
|
84
39
|
it '#address' do
|
85
|
-
provider.address.
|
40
|
+
provider.address.must_be_instance_of NfeReader::Address
|
86
41
|
end
|
87
|
-
|
88
|
-
it '#neighborhood' do
|
89
|
-
provider.neighborhood.must_equal 'Neighborhood'
|
90
|
-
end
|
91
|
-
|
92
|
-
it '#city_code' do
|
93
|
-
provider.city_code.must_equal '1246'
|
94
|
-
end
|
95
|
-
|
96
|
-
it '#city' do
|
97
|
-
provider.city.must_equal 'City'
|
98
|
-
end
|
99
|
-
|
100
|
-
it '#state' do
|
101
|
-
provider.state.must_equal 'ST'
|
102
|
-
end
|
103
|
-
|
104
|
-
it '#country_code' do
|
105
|
-
provider.country_code.must_equal '1058'
|
106
|
-
end
|
107
|
-
|
108
|
-
it '#country' do
|
109
|
-
provider.country.must_equal 'Brazil'
|
110
|
-
end
|
111
|
-
|
112
|
-
it '#zip_code' do
|
113
|
-
provider.zip_code.must_equal '00000-000'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'without address' do
|
118
|
-
let(:provider) { Nfe::Reader::Provider.new }
|
119
|
-
|
120
|
-
it '#phone' do
|
121
|
-
provider.number.must_be_nil
|
122
|
-
end
|
123
|
-
|
124
|
-
it '#number' do
|
125
|
-
provider.number.must_be_nil
|
126
|
-
end
|
127
|
-
|
128
|
-
it '#address' do
|
129
|
-
provider.address.must_be_nil
|
130
|
-
end
|
131
|
-
it '#neighborhood' do
|
132
|
-
provider.neighborhood.must_be_nil
|
133
|
-
end
|
134
|
-
|
135
|
-
it '#city_code' do
|
136
|
-
provider.city_code.must_be_nil
|
137
|
-
end
|
138
|
-
|
139
|
-
it '#city' do
|
140
|
-
provider.city.must_be_nil
|
141
|
-
end
|
142
|
-
|
143
|
-
it '#state' do
|
144
|
-
provider.state.must_be_nil
|
145
|
-
end
|
146
|
-
|
147
|
-
it '#country_code' do
|
148
|
-
provider.country_code.must_be_nil
|
149
|
-
end
|
150
|
-
|
151
|
-
it '#country' do
|
152
|
-
provider.country.must_be_nil
|
153
|
-
end
|
154
|
-
end
|
155
42
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe NfeReader::Purchase do
|
4
4
|
def nfe_hash
|
5
5
|
{
|
6
6
|
compra: {
|
@@ -11,7 +11,7 @@ describe Nfe::Reader::Purchase do
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:purchase) {
|
14
|
+
let(:purchase) { NfeReader::Purchase.new(nfe_hash[:compra]) }
|
15
15
|
|
16
16
|
it '#number' do
|
17
17
|
purchase.number.must_equal '10001'
|