boa_vista 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTYyM2M0NDhiYTgzY2RjNzA5YmIyYzE5NGM0M2ZmM2U5NTc2Y2FlMA==
4
+ MDEwM2FlZTY0ODFmMWI1NTA2ODQyNWYxMzNkNzg5ZmYzYWYzNmZkMA==
5
5
  data.tar.gz: !binary |-
6
- NTA0MTJhZDlkMTM1YWI1ZTA2ZTg4ZTBiMzgwZDRkMWE4NGVjMDQ5Ng==
6
+ NTE2NDQ4MDA3YTMyOWQ3MmY5NDA4YTNlN2Y4NWI5ODFhNTQwNWViZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWJmZmIxOTk0OGI3OWI1ZTNjYjhjZjVmYTc0NzlhNTJmYmEyN2E3OWM3M2My
10
- Mjk1MDZjODY0OGY2YjhiYzY2N2QyYzA5ZmY3ZmM2NTc1NzE3YTcwZGZlOTAy
11
- ZWU5NGU3MDBhNGI2MTRkNDc0YTkwNjcxNDc2NTQ3NGYwZGExZTA=
9
+ OTRhOWI5MGNhNDRhMzU3Y2Q3MTFhOGY3NzQ3YWYyOWJhMmMxMjg5MWI1NmNm
10
+ MmFmNDE0NDg5Yjc5ZWQ3NmZkNTE0YzJmZjFiYTNkMzRiMmU5NDdiMTllYzc0
11
+ MTJhMjM4ZWUwZGY3YzNjNjhmNjQ5YTVjNDI3YWQ2MWU5MzVjOTY=
12
12
  data.tar.gz: !binary |-
13
- OTcwYjZlMjgzNTFlN2M2NGMyNTQ2YTViYjg1YzE2MGEwMGFiNTM4NTk1NDI5
14
- NTkxMWEwYjg5M2E1ODNlNTNjYTFkY2QzZWMwOWZhZDgwODQ0MTc1NGZkZDEy
15
- YjdmODEyODY1MGJlZGY2MjhmYTdjNTcxYTA0OTYzMTU1Yzc0Mzc=
13
+ YmVkYWIzMTQyY2VhNDJlMGZhNzY0OTI3MDBhNWE0NGQ4Y2YzZGFhNzZkMGNk
14
+ ZDQ5YTgyMTE4NDYxOTY5NTA5ZjQ5MTExN2YzNGVhOTUyNmE1NjIxZGFlZmI0
15
+ M2EzMjI0NWM3NjMyMWIzYzZkYjk5ZTVkMTQ4YzNjMmQyNDdlZDY=
@@ -4,9 +4,9 @@ module BoaVista
4
4
  module_function
5
5
 
6
6
  def attributes
7
- BoaVista::Request::Layout.attributes.merge(company_name: { range: 84..133 },
8
- facilitator_code: { range: 134..141 },
9
- end_text_indicator: { range: 142..142 })
7
+ BoaVista::Request::Layout.attributes.merge(company_name: { range: 83..132 },
8
+ facilitator_code: { range: 133..140 },
9
+ end_text_indicator: { range: 141..141 })
10
10
  end
11
11
  end
12
12
  end
@@ -4,7 +4,7 @@ module BoaVista
4
4
  module_function
5
5
 
6
6
  def attributes
7
- BoaVista::Request::Layout.attributes.merge(end_text_indicator: { range: 84..84 })
7
+ BoaVista::Request::Layout.attributes.merge(end_text_indicator: { range: 83..83 })
8
8
  end
9
9
  end
10
10
  end
@@ -5,19 +5,20 @@ module BoaVista
5
5
 
6
6
  def attributes
7
7
  {
8
- transaction: { range: 1..8 },
9
- version: { range: 9..10 },
10
- reserved_requester: { range: 11..20 },
11
- reserved_boa_vista: { range: 21..40 },
12
- code: { range: 41..48 },
13
- password: { range: 49..56 },
14
- query: { range: 57..64 },
15
- query_version: { range: 65..66 },
16
- response_type: { range: 67..67 },
17
- response_transmission_type: { range: 68..68 },
18
- document_type: { range: 69..69 },
19
- document_number: { range: 70..83 }
8
+ transaction: { range: 0..7 },
9
+ version: { range: 8..9 },
10
+ reserved_requester: { range: 10..19 },
11
+ reserved_boa_vista: { range: 20..39 },
12
+ code: { range: 40..47 },
13
+ password: { range: 48..55 },
14
+ query: { range: 56..63 },
15
+ query_version: { range: 64..65 },
16
+ response_type: { range: 66..66 },
17
+ response_transmission_type: { range: 67..67 },
18
+ document_type: { range: 68..68 },
19
+ document_number: { range: 69..82 }
20
20
  }
21
+
21
22
  end
22
23
  end
23
24
  end
@@ -10,20 +10,32 @@ module BoaVista
10
10
  end
11
11
 
12
12
  def create
13
- write_line_with(layout)
13
+ write_line_with(self.class.layout(@values[:document_type]))
14
14
  end
15
15
 
16
- private
16
+ def self.read(line)
17
+ document_type = line.slice(68..68)
18
+ BoaVista::Line.prepare_for_read(line, layout(document_type)).read
19
+ end
17
20
 
18
- def layout
19
- case @values[:document_type].to_i
21
+ def self.layout(document_type)
22
+ case document_type.to_i
20
23
  when DOCUMENT_TYPE[:cpf] then BoaVista::Request::Layout::Cpf
21
24
  when DOCUMENT_TYPE[:cnpj] then BoaVista::Request::Layout::Cnpj
22
25
  else
23
- fail BoaVista::Errors::InvalidDocumentType.new("Invalid document type: #{@values[:document_type]}")
26
+ fail BoaVista::Errors::InvalidDocumentType.new("Invalid document type: #{document_type}")
24
27
  end
25
28
  end
26
29
 
30
+ def self.document_name(document_type)
31
+ DOCUMENT_TYPE.each do |k, v|
32
+ return k if document_type.to_i == v
33
+ end
34
+ return false
35
+ end
36
+
37
+ private
38
+
27
39
  def write_line_with(layout)
28
40
  BoaVista::Line.prepare_for_write(@values, layout).write
29
41
  end
@@ -7,15 +7,15 @@ module BoaVista
7
7
 
8
8
  def attributes
9
9
  default_attributes.merge(query_online: { range: 77..77 },
10
- name: { range: 78..127 },
11
- document: { range: 128..138 },
12
- birthday_date: { range: 139..146 },
13
- mothers_name: { range: 149..198 },
14
- voter_registration: { range: 199..211 },
15
- condition: { range: 212..212 },
16
- query_date: { range: 213..220 },
17
- query_time: { range: 221..226 },
18
- protocol: { range: 227..246 })
10
+ name: { range: 78..137 },
11
+ document: { range: 138..148 },
12
+ birthday_date: { range: 149..156 },
13
+ mothers_name: { range: 157..206 },
14
+ voter_registration: { range: 207..219 },
15
+ condition: { range: 220..220 },
16
+ query_date: { range: 221..228 },
17
+ query_time: { range: 229..234 },
18
+ protocol: { range: 235..254 })
19
19
  end
20
20
 
21
21
  def condition_options
@@ -7,27 +7,27 @@ module BoaVista
7
7
 
8
8
  def attributes
9
9
  default_attributes.merge(record: { range: 77..77 },
10
- document_number: { range: 78..91 },
11
- nire: { range: 92..102 },
12
- company_name: { range: 103..217 },
13
- condition: { range: 218..218 },
14
- foundation_date: { range: 219..226 },
15
- registration: { range: 227..240 },
16
- registration_status: { range: 241..241 },
17
- address: { range: 242..311 },
18
- district: { range: 312..331 },
19
- postal_code: { range: 332..339 },
20
- city: { range: 340..379 },
21
- uf: { range: 380..381 },
22
- phone_1: { range: 382..401 },
23
- phone_2: { range: 402..416 },
24
- fax: { range: 417..431 },
25
- ibge_code: { range: 432..439 },
26
- legal_nature_code: { range: 440..447 },
27
- legal_nature_description: { range: 448..502 },
28
- segment: { range: 503..581 },
29
- hive_activity_code: { range: 582..589 },
30
- hive_activity_description: { range: 590..644 })
10
+ document_number: { range: 78..91 },
11
+ nire: { range: 92..102 },
12
+ company_name: { range: 103..217 },
13
+ condition: { range: 218..218 },
14
+ foundation_date: { range: 219..226 },
15
+ registration: { range: 227..240 },
16
+ registration_status: { range: 241..241 },
17
+ address: { range: 242..311 },
18
+ district: { range: 312..331 },
19
+ postal_code: { range: 332..339 },
20
+ city: { range: 340..379 },
21
+ uf: { range: 380..381 },
22
+ phone_1: { range: 382..401 },
23
+ phone_2: { range: 402..416 },
24
+ fax: { range: 417..431 },
25
+ ibge_code: { range: 432..439 },
26
+ legal_nature_code: { range: 440..447 },
27
+ legal_nature_description: { range: 448..502 },
28
+ segment: { range: 503..581 },
29
+ hive_activity_code: { range: 582..589 },
30
+ hive_activity_description: { range: 590..644 })
31
31
  end
32
32
 
33
33
  def condition_options
@@ -1,3 +1,3 @@
1
1
  module BoaVista
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1 +1 @@
1
- TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZ249QNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN3073086661025121982MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMVVVVVVVVVVVVVCDDDDDDDDTTTTTTPPPPPPPPPPPPPPPPPPPP
1
+ TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZ249QNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN3073086661025121982MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMVVVVVVVVVVVVVCDDDDDDDDTTTTTTPPPPPPPPPPPPPPPPPPPP
@@ -0,0 +1 @@
1
+ CSR60 01 00000045HOM033 SINTON 012C100012345678900X
@@ -20,12 +20,12 @@ RSpec.describe BoaVista::Request::Layout::Cnpj do
20
20
 
21
21
  context 'cnpj attributes' do
22
22
  it { is_expected.to have_key(:company_name) }
23
- its([:company_name, :range]) { is_expected.to eq(84..133) }
23
+ its([:company_name, :range]) { is_expected.to eq(83..132) }
24
24
 
25
25
  it { is_expected.to have_key(:facilitator_code) }
26
- its([:facilitator_code, :range]) { is_expected.to eq(134..141) }
26
+ its([:facilitator_code, :range]) { is_expected.to eq(133..140) }
27
27
 
28
28
  it { is_expected.to have_key(:end_text_indicator) }
29
- its([:end_text_indicator, :range]) { is_expected.to eq(142..142) }
29
+ its([:end_text_indicator, :range]) { is_expected.to eq(141..141) }
30
30
  end
31
31
  end
@@ -21,8 +21,8 @@ RSpec.describe BoaVista::Request::Layout::Cpf do
21
21
  it 'includes the end_text_indicator with the right range' do
22
22
  expect(subject).to have_key(:end_text_indicator)
23
23
 
24
- expect(subject[:end_text_indicator][:range]).to cover(84)
25
- expect(subject[:end_text_indicator][:range]).to_not cover(83)
26
- expect(subject[:end_text_indicator][:range]).to_not cover(85)
24
+ expect(subject[:end_text_indicator][:range]).to cover(83)
25
+ expect(subject[:end_text_indicator][:range]).to_not cover(82)
26
+ expect(subject[:end_text_indicator][:range]).to_not cover(84)
27
27
  end
28
28
  end
@@ -2,17 +2,17 @@ RSpec.describe BoaVista::Request::Layout do
2
2
  describe 'attributes_mapping_methods' do
3
3
  subject { described_class.attributes }
4
4
 
5
- its([:transaction, :range]) { is_expected.to eq(1..8) }
6
- its([:version, :range]) { is_expected.to eq(9..10) }
7
- its([:reserved_requester, :range]) { is_expected.to eq(11..20) }
8
- its([:reserved_boa_vista, :range]) { is_expected.to eq(21..40) }
9
- its([:code, :range]) { is_expected.to eq(41..48) }
10
- its([:password, :range]) { is_expected.to eq(49..56) }
11
- its([:query, :range]) { is_expected.to eq(57..64) }
12
- its([:query_version, :range]) { is_expected.to eq(65..66) }
13
- its([:response_type, :range]) { is_expected.to eq(67..67) }
14
- its([:response_transmission_type, :range]) { is_expected.to eq(68..68) }
15
- its([:document_type, :range]) { is_expected.to eq(69..69) }
16
- its([:document_number, :range]) { is_expected.to eq(70..83) }
5
+ its([:transaction, :range]) { is_expected.to eq(0..7) }
6
+ its([:version, :range]) { is_expected.to eq(8..9) }
7
+ its([:reserved_requester, :range]) { is_expected.to eq(10..19) }
8
+ its([:reserved_boa_vista, :range]) { is_expected.to eq(20..39) }
9
+ its([:code, :range]) { is_expected.to eq(40..47) }
10
+ its([:password, :range]) { is_expected.to eq(48..55) }
11
+ its([:query, :range]) { is_expected.to eq(56..63) }
12
+ its([:query_version, :range]) { is_expected.to eq(64..65) }
13
+ its([:response_type, :range]) { is_expected.to eq(66..66) }
14
+ its([:response_transmission_type, :range]) { is_expected.to eq(67..67) }
15
+ its([:document_type, :range]) { is_expected.to eq(68..68) }
16
+ its([:document_number, :range]) { is_expected.to eq(69..82) }
17
17
  end
18
18
  end
@@ -2,42 +2,53 @@ RSpec.describe BoaVista::Request do
2
2
 
3
3
  let(:instance) { described_class.new(values) }
4
4
 
5
- subject { instance.create }
6
-
7
- context 'when document is cpf' do
8
- let(:values) do
9
- {
10
- document_type: '1',
11
- document_number: '00031030944410'
12
- }.merge(BoaVista::Request::Default::CPF)
13
- end
5
+ describe '#create' do
6
+
7
+ subject { instance.create }
8
+
9
+ context 'when document is cpf' do
10
+ let(:values) do
11
+ {
12
+ document_type: '1',
13
+ document_number: '00031030944410'
14
+ }.merge(BoaVista::Request::Default::CPF)
15
+ end
14
16
 
15
- let(:document_type) { values[:document_type] }
17
+ let(:document_type) { values[:document_type] }
16
18
 
17
- it 'writes document number in the right position' do
18
- expect(subject.slice(69..82)).to eq('00031030944410')
19
+ it 'writes document number in the right position' do
20
+ expect(subject.slice(69..82)).to eq('00031030944410')
21
+ end
19
22
  end
20
- end
21
23
 
22
- context 'when document is cnpj' do
23
- let(:values) do
24
- {
25
- document_type: '2',
26
- document_number: '12345678901234'
27
- }.merge(BoaVista::Request::Default::CNPJ)
24
+ context 'when document is cnpj' do
25
+ let(:values) do
26
+ {
27
+ document_type: '2',
28
+ document_number: '12345678901234'
29
+ }.merge(BoaVista::Request::Default::CNPJ)
30
+ end
31
+
32
+ let(:document_type) { values[:document_type] }
33
+
34
+ it 'writes document number in the right position' do
35
+ expect(subject.slice(69..82)).to eq('12345678901234')
36
+ end
28
37
  end
29
38
 
30
- let(:document_type) { values[:document_type] }
39
+ context 'when invalid document type' do
40
+ let(:values) { Hash.new }
41
+ let(:document_type) { '3' }
31
42
 
32
- it 'writes document number in the right position' do
33
- expect(subject.slice(69..82)).to eq('12345678901234')
43
+ it { expect { subject }.to raise_error(BoaVista::Errors::InvalidDocumentType) }
34
44
  end
35
45
  end
36
46
 
37
- context 'when invalid document type' do
38
- let(:values) { Hash.new }
39
- let(:document_type) { '3' }
47
+ describe '.read' do
48
+ let(:line) { File.read('./spec/fixtures/request_cpf.txt') }
49
+ subject { described_class.read(line) }
40
50
 
41
- it { expect { subject }.to raise_error(BoaVista::Errors::InvalidDocumentType) }
51
+ its(:document_number) { is_expected.to eq('00012345678900') }
52
+ its(:document_type) { is_expected.to eq('1') }
42
53
  end
43
54
  end
@@ -8,7 +8,7 @@ RSpec.describe BoaVista::Response::Layout::Layout249 do
8
8
 
9
9
  its(:transaction) { is_expected.to eq('T' * 8) }
10
10
  its(:query_online) { is_expected.to eq('Q' * 1) }
11
- its(:name) { is_expected.to eq('N' * 50) }
11
+ its(:name) { is_expected.to eq('N' * 60) }
12
12
  its(:document) { is_expected.to eq('30730866610') }
13
13
  its(:birthday_date) { is_expected.to eq('25121982') }
14
14
  its(:mothers_name) { is_expected.to eq('M' * 50) }
@@ -1,3 +1,3 @@
1
1
  RSpec.describe BoaVista::VERSION do
2
- specify { expect(BoaVista::VERSION).to eq '0.0.5' }
2
+ specify { expect(BoaVista::VERSION).to eq '0.0.6' }
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boa_vista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Souza
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-15 00:00:00.000000000 Z
12
+ date: 2016-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -67,20 +67,6 @@ dependencies:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: pry
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ! '>='
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: rspec-its
86
72
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +148,7 @@ files:
162
148
  - spec/fixtures/layout_999.txt
163
149
  - spec/fixtures/layout_cpf.txt
164
150
  - spec/fixtures/layout_invalid_353.txt
151
+ - spec/fixtures/request_cpf.txt
165
152
  - spec/fixtures/response_with_html.txt
166
153
  - spec/fixtures/unknown_layout.txt
167
154
  - spec/lib/boa_vista/client_spec.rb
@@ -230,6 +217,7 @@ test_files:
230
217
  - spec/fixtures/layout_999.txt
231
218
  - spec/fixtures/layout_cpf.txt
232
219
  - spec/fixtures/layout_invalid_353.txt
220
+ - spec/fixtures/request_cpf.txt
233
221
  - spec/fixtures/response_with_html.txt
234
222
  - spec/fixtures/unknown_layout.txt
235
223
  - spec/lib/boa_vista/client_spec.rb