afd_parser 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/afd_parser.rb +257 -0
- data/lib/afd_parser/clock_in_out.rb +71 -0
- data/lib/afd_parser/header.rb +144 -0
- data/lib/afd_parser/record_parser.rb +65 -0
- data/lib/afd_parser/set_employee.rb +98 -0
- data/lib/afd_parser/set_employer.rb +109 -0
- data/lib/afd_parser/set_time.rb +77 -0
- data/lib/afd_parser/trailer.rb +83 -0
- data/lib/afd_parser/version.rb +3 -0
- data/test/afd_file +11 -0
- data/test/afd_invalid_utf-8_chars +2 -0
- data/test/afd_parser_test.rb +633 -0
- data/test/clock_in_out_test.rb +32 -0
- data/test/header_test.rb +52 -0
- data/test/set_employee_test.rb +67 -0
- data/test/set_employer_test.rb +29 -0
- data/test/set_time_test.rb +23 -0
- data/test/test_helper.rb +25 -0
- data/test/trailer_test.rb +26 -0
- metadata +85 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'afd_parser'
|
3
|
+
|
4
|
+
class ClockInOutTest < Test::Unit::TestCase
|
5
|
+
TEMPLATE = "0000000073190220111814111111111111"
|
6
|
+
|
7
|
+
def test_equal
|
8
|
+
# equal
|
9
|
+
assert AfdParser::ClockInOut.new(TEMPLATE) == AfdParser::ClockInOut.new(TEMPLATE)
|
10
|
+
|
11
|
+
# different record types:
|
12
|
+
assert !(AfdParser::ClockInOut.new(TEMPLATE) == AfdParser::SetTime.new("0000000014280120111112280120111113"))
|
13
|
+
|
14
|
+
# different id:
|
15
|
+
assert !(AfdParser::ClockInOut.new(TEMPLATE) == AfdParser::ClockInOut.new("0000000083190220111814111111111111"))
|
16
|
+
|
17
|
+
# different time:
|
18
|
+
assert !(AfdParser::ClockInOut.new(TEMPLATE) == AfdParser::ClockInOut.new("0000000073190220111815111111111111"))
|
19
|
+
|
20
|
+
# different PIS:
|
21
|
+
assert !(AfdParser::ClockInOut.new(TEMPLATE) == AfdParser::ClockInOut.new("0000000073190220111814111111111112"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_parse_11_digit_pis
|
25
|
+
line = "000000007319022011181411111111111\r\n"
|
26
|
+
cio = AfdParser::ClockInOut.new line
|
27
|
+
assert_equal 7, cio.line_id
|
28
|
+
assert_equal 3, cio.record_type_id
|
29
|
+
assert_equal Time.local(2011,2,19,18,14), cio.creation_time
|
30
|
+
assert_equal 11111111111, cio.pis
|
31
|
+
end
|
32
|
+
end
|
data/test/header_test.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'afd_parser'
|
3
|
+
|
4
|
+
class HeaderTest < Test::Unit::TestCase
|
5
|
+
TEMPLATE = "0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044032001201122022011210220111048"
|
6
|
+
|
7
|
+
def test_equal
|
8
|
+
# equal
|
9
|
+
assert AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new(TEMPLATE)
|
10
|
+
|
11
|
+
# different record types:
|
12
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::SetTime.new("0000000024280120111112280120111113"))
|
13
|
+
|
14
|
+
# different id:
|
15
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000011200000000067890000000009876RAZAO_SOCIAL 000040000700044032001201122022011210220111048"))
|
16
|
+
|
17
|
+
# different employer type:
|
18
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001100000000067890000000009876RAZAO_SOCIAL 000040000700044032001201122022011210220111048"))
|
19
|
+
|
20
|
+
# different employer document:
|
21
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000567890000000009876RAZAO_SOCIAL 000040000700044032001201122022011210220111048"))
|
22
|
+
|
23
|
+
# different employer cei:
|
24
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000067890000000019876RAZAO_SOCIAL 000040000700044032001201122022011210220111048"))
|
25
|
+
|
26
|
+
# different employer name:
|
27
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000067890000000009876RACAO_SOCIAL 111141111711144132001201122022011210220111048"))
|
28
|
+
|
29
|
+
# different start date:
|
30
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044032000201122022011210220111048"))
|
31
|
+
|
32
|
+
# different end date:
|
33
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044032001201122022012210220111048"))
|
34
|
+
|
35
|
+
# different afd creation time:
|
36
|
+
assert !(AfdParser::Header.new(TEMPLATE) == AfdParser::Header.new("0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044032001201122022011210220121048"))
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_corrupted_date_parsing
|
41
|
+
# corrupted times:
|
42
|
+
header = AfdParser::Header.new("0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044034001201132022011320220121048")
|
43
|
+
assert_equal '40012011', header.afd_start_date
|
44
|
+
assert_equal '32022011', header.afd_end_date
|
45
|
+
assert_equal '320220121048', header.afd_creation_time
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_corrupted_date_exporting
|
49
|
+
header = AfdParser::Header.new("0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044034001201132022011320220121048")
|
50
|
+
assert_equal '0000000001200000000067890000000009876RAZAO_SOCIAL 000040000700044034001201132022011320220121048', header.export
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
require 'afd_parser'
|
4
|
+
|
5
|
+
class SetEmployeeTest < Test::Unit::TestCase
|
6
|
+
def test_parsing
|
7
|
+
# normal 12 digits:
|
8
|
+
record = AfdParser::SetEmployee.new("0000000045080220111709I222222222222FULANO DE TAL ")
|
9
|
+
assert_equal 222222222222, record.pis
|
10
|
+
assert_equal 4, record.line_id
|
11
|
+
assert_equal 5, record.record_type_id
|
12
|
+
assert_equal DateTime.civil(2011,2,8,19,9).to_time, record.creation_time
|
13
|
+
assert_equal :add, record.operation_type
|
14
|
+
assert_equal "FULANO DE TAL", record.name
|
15
|
+
|
16
|
+
# normal 11 digits:
|
17
|
+
record = AfdParser::SetEmployee.new("0000000045080220111709I22222222222FULANO DE TAL ")
|
18
|
+
assert_equal 22222222222, record.pis
|
19
|
+
assert_equal 4, record.line_id
|
20
|
+
assert_equal 5, record.record_type_id
|
21
|
+
assert_equal DateTime.civil(2011,2,8,19,9).to_time, record.creation_time
|
22
|
+
assert_equal :add, record.operation_type
|
23
|
+
assert_equal "FULANO DE TAL", record.name
|
24
|
+
|
25
|
+
# error: 1 zero digit:
|
26
|
+
record = AfdParser::SetEmployee.new("0000000045080220111709I0FULANO DE TAL ")
|
27
|
+
assert_equal 0, record.pis
|
28
|
+
assert_equal 4, record.line_id
|
29
|
+
assert_equal 5, record.record_type_id
|
30
|
+
assert_equal DateTime.civil(2011,2,8,19,9).to_time, record.creation_time
|
31
|
+
assert_equal :add, record.operation_type
|
32
|
+
assert_equal "FULANO DE TAL", record.name
|
33
|
+
|
34
|
+
# with non-ASCII chars:
|
35
|
+
record = AfdParser::SetEmployee.new("0000000045080220111709I22222222222FUL\xC3NO DE TAL ".force_encoding("ISO-8859-1"))
|
36
|
+
assert_equal 22222222222, record.pis
|
37
|
+
assert_equal 4, record.line_id
|
38
|
+
assert_equal 5, record.record_type_id
|
39
|
+
assert_equal DateTime.civil(2011,2,8,19,9).to_time, record.creation_time
|
40
|
+
assert_equal :add, record.operation_type
|
41
|
+
assert_equal "FULÃNO DE TAL", record.name
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_equal
|
45
|
+
template = "0000000045080220111709I222222222222TESTE 2 ".freeze
|
46
|
+
# equal
|
47
|
+
assert AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new(template)
|
48
|
+
|
49
|
+
# different record types:
|
50
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetTime.new("0000000014280120111112280120111113"))
|
51
|
+
|
52
|
+
# different id:
|
53
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new("0000000055080220111709I222222222222TESTE 2 "))
|
54
|
+
|
55
|
+
# different time:
|
56
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new("0000000045080220121709I222222222222TESTE 2 "))
|
57
|
+
|
58
|
+
# different operation:
|
59
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new("0000000045080220111709A222222222222TESTE 2 "))
|
60
|
+
|
61
|
+
# different PIS:
|
62
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new("0000000045080220111709I333333333333TESTE 2 "))
|
63
|
+
|
64
|
+
# different name:
|
65
|
+
assert !(AfdParser::SetEmployee.new(template) == AfdParser::SetEmployee.new("0000000045080220111709I222222222222FULANO DE TAL "))
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'afd_parser'
|
3
|
+
|
4
|
+
class SetEmployerTest < Test::Unit::TestCase
|
5
|
+
TEMPLATE = "0000000022270120111756108682040000172000000000000O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "
|
6
|
+
|
7
|
+
def test_equal
|
8
|
+
# equal
|
9
|
+
assert AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new(TEMPLATE)
|
10
|
+
|
11
|
+
# different record types:
|
12
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetTime.new("0000000014280120111112280120111113"))
|
13
|
+
|
14
|
+
# different id:
|
15
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000032270120111756108682040000172000000000000O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "))
|
16
|
+
# different time:
|
17
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120121756108682040000172000000000000O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "))
|
18
|
+
# different document type:
|
19
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120111756208682040000172000000000000O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "))
|
20
|
+
# different document number:
|
21
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120111756111111111111111000000000000O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "))
|
22
|
+
# different CEI:
|
23
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120111756108682040000172222222222222O.S. SYSTEMS SOFTWARES LTDA. PELOTAS - RS "))
|
24
|
+
# different name:
|
25
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120111756108682040000172000000000000SUPER COMPANY INCORPORATED PELOTAS - RS "))
|
26
|
+
# different location:
|
27
|
+
assert !(AfdParser::SetEmployer.new(TEMPLATE) == AfdParser::SetEmployer.new("0000000022270120111756108682040000172000000000000O.S. SYSTEMS SOFTWARES LTDA. NEVERLAND - DISNEYLAND "))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'afd_parser'
|
3
|
+
|
4
|
+
class SetTimeTest < Test::Unit::TestCase
|
5
|
+
TEMPLATE = "0000000014280120111112280120111113"
|
6
|
+
|
7
|
+
def test_equal
|
8
|
+
# equal
|
9
|
+
assert AfdParser::SetTime.new(TEMPLATE) == AfdParser::SetTime.new(TEMPLATE)
|
10
|
+
|
11
|
+
# different record types:
|
12
|
+
assert !(AfdParser::SetTime.new(TEMPLATE) == AfdParser::ClockInOut.new("0000000014280120111112280120111113"))
|
13
|
+
|
14
|
+
# different id:
|
15
|
+
assert !(AfdParser::SetTime.new(TEMPLATE) == AfdParser::SetTime.new("0000000024280120111112280120111113"))
|
16
|
+
|
17
|
+
# different before time:
|
18
|
+
assert !(AfdParser::SetTime.new(TEMPLATE) == AfdParser::SetTime.new("0000000014280120121112280120111113"))
|
19
|
+
|
20
|
+
# different after time:
|
21
|
+
assert !(AfdParser::SetTime.new(TEMPLATE) == AfdParser::SetTime.new("0000000014280120111112280120121113"))
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Controle de Horas - Sistema para gestão de horas trabalhadas
|
2
|
+
# Copyright (C) 2009 O.S. Systems Softwares Ltda.
|
3
|
+
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Affero General Public License as
|
6
|
+
# published by the Free Software Foundation, either version 3 of the
|
7
|
+
# License, or (at your option) any later version.
|
8
|
+
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Affero General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU Affero General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
# Rua Clóvis Gularte Candiota 132, Pelotas-RS, Brasil.
|
18
|
+
# e-mail: contato@ossystems.com.br
|
19
|
+
|
20
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
21
|
+
|
22
|
+
require 'test/unit'
|
23
|
+
|
24
|
+
class Test::Unit::TestCase
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'afd_parser'
|
3
|
+
|
4
|
+
class TrailerTest < Test::Unit::TestCase
|
5
|
+
TEMPLATE = ["9999999990000000010000000030000000010000000049", {:set_employer => 1, :clock_in_out => 3, :set_time => 1, :set_employee => 4}]
|
6
|
+
|
7
|
+
def test_equal
|
8
|
+
# equal
|
9
|
+
assert AfdParser::Trailer.new(*TEMPLATE) == AfdParser::Trailer.new(*TEMPLATE)
|
10
|
+
|
11
|
+
# different record types:
|
12
|
+
assert !(AfdParser::Trailer.new(*TEMPLATE) == AfdParser::SetTime.new("0000000014280120111112280120111113"))
|
13
|
+
|
14
|
+
# different set employer count:
|
15
|
+
assert !(AfdParser::Trailer.new(*TEMPLATE) == AfdParser::Trailer.new("9999999990000000020000000030000000010000000049", {:set_employer => 2, :clock_in_out => 3, :set_time => 1, :set_employee => 4}))
|
16
|
+
|
17
|
+
# different clock_in_out count:
|
18
|
+
assert !(AfdParser::Trailer.new(*TEMPLATE) == AfdParser::Trailer.new("9999999990000000010000000040000000010000000049", {:set_employer => 1, :clock_in_out => 4, :set_time => 1, :set_employee => 4}))
|
19
|
+
|
20
|
+
# different set_time count:
|
21
|
+
assert !(AfdParser::Trailer.new(*TEMPLATE) == AfdParser::Trailer.new("9999999990000000010000000030000000020000000049", {:set_employer => 1, :clock_in_out => 3, :set_time => 2, :set_employee => 4}))
|
22
|
+
|
23
|
+
# different:
|
24
|
+
assert !(AfdParser::Trailer.new(*TEMPLATE) == AfdParser::Trailer.new("9999999990000000010000000030000000010000000059", {:set_employer => 1, :clock_in_out => 3, :set_time => 1, :set_employee => 5}))
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: afd_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- O.S. Systems Softwares Ltda.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.7
|
27
|
+
description: Use this gem to verify and parse data files generated from REPs.
|
28
|
+
email: contato@ossystems.com.br
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/afd_parser.rb
|
34
|
+
- lib/afd_parser/clock_in_out.rb
|
35
|
+
- lib/afd_parser/header.rb
|
36
|
+
- lib/afd_parser/record_parser.rb
|
37
|
+
- lib/afd_parser/set_employee.rb
|
38
|
+
- lib/afd_parser/set_employer.rb
|
39
|
+
- lib/afd_parser/set_time.rb
|
40
|
+
- lib/afd_parser/trailer.rb
|
41
|
+
- lib/afd_parser/version.rb
|
42
|
+
- test/afd_file
|
43
|
+
- test/afd_invalid_utf-8_chars
|
44
|
+
- test/afd_parser_test.rb
|
45
|
+
- test/clock_in_out_test.rb
|
46
|
+
- test/header_test.rb
|
47
|
+
- test/set_employee_test.rb
|
48
|
+
- test/set_employer_test.rb
|
49
|
+
- test/set_time_test.rb
|
50
|
+
- test/test_helper.rb
|
51
|
+
- test/trailer_test.rb
|
52
|
+
homepage: http://www.ossystems.com.br/
|
53
|
+
licenses: []
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.6.11
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Gem to parse AFDs from REPs
|
75
|
+
test_files:
|
76
|
+
- test/set_employer_test.rb
|
77
|
+
- test/header_test.rb
|
78
|
+
- test/afd_parser_test.rb
|
79
|
+
- test/test_helper.rb
|
80
|
+
- test/set_time_test.rb
|
81
|
+
- test/trailer_test.rb
|
82
|
+
- test/afd_invalid_utf-8_chars
|
83
|
+
- test/afd_file
|
84
|
+
- test/set_employee_test.rb
|
85
|
+
- test/clock_in_out_test.rb
|