Skip to content

Commit

Permalink
Merge pull request jrperin#7 from jrperin/feature/reestrutura
Browse files Browse the repository at this point in the history
reestrutura das definicoes
  • Loading branch information
jrperin authored Aug 21, 2023
2 parents 84c735d + 7529b5d commit 1070fd0
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 73 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.0.4] - 2023-08-20

### Added
New extractor added to interpret fields without specifying decimal
* S9(10)V - S9\(([0-9]+)\)V$ FieldSignalNumeric1Decimals3

## [1.0.3] - 2021-09-15

### Added
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,33 +132,33 @@ Table of types treated by CobolJsonifier
TYPES CLASSES EBCDIC ASCII
=======================================================================================
-[Empty]--------------------------------------------------------------------------
00 Empty Content Fieldempty yes yes
00) Empty Content Fieldempty yes yes
-[Numeric Types without signal]---------------------------------------------------
01) 9 FieldSimpleNumeric yes yes
02) 9V99 FieldSimpleNumericDecimals1 yes yes
03) 9V9(2) FieldSimpleNumericDecimals2 yes yes
04) 9(12) FieldSimpleNumeric1 yes yes
05) 9(12)V99 FieldSimpleNumeric1Decimals1 yes yes
06) 9(12)V9(2) FieldSimpleNumeric1Decimals2 yes yes
01) 9 FieldSimpleNumeric yes yes
02) 9V99 FieldSimpleNumericDecimals1 yes yes
03) 9V9(2) FieldSimpleNumericDecimals2 yes yes
04) 9(12) FieldSimpleNumeric1 yes yes
05) 9(12)V99 FieldSimpleNumeric1Decimals1 yes yes
06) 9(12)V9(2) FieldSimpleNumeric1Decimals2 yes yes
-[Numeric Types with signal]------------------------------------------------------
07) S9(12) [BINARY/COMP3] FieldSignalNumeric1 yes no
08) S9(12)V99 [BINARY/COMP3] FieldSignalNumeric1Decimals1 yes no
09) S9(12)V9(2) [BINARY/COMP3] FieldSignalNumeric1Decimals2 yes no
07) S9(12) [BINARY/COMP3] FieldSignalNumeric1 yes no
08) S9(12)V99 [BINARY/COMP3] FieldSignalNumeric1Decimals1 yes no
09) S9(12)V9(2) [BINARY/COMP3] FieldSignalNumeric1Decimals2 yes no
10) S9(12)V [BINARY/COMP3] FieldSignalNumeric1Decimals3 yes no
-[Masked Numeric Types]-----------------------------------------------------------
A1) +99999999999999.99 FieldNumericMasked1 no yes
-99999999999999.99
+99999999999999
+ZZZZZZZZZZZZZ9.99
-ZZZZZZZZZZZZZ9.99 (Note: These are just
ZZZZZZZZZZZZZZ.ZZ some examples)
99999999999999999
A01) +99999999999999.99 FieldNumericMasked1 no yes
-99999999999999.99
+99999999999999
+ZZZZZZZZZZZZZ9.99
-ZZZZZZZZZZZZZ9.99 (Note: These are just
ZZZZZZZZZZZZZZ.ZZ some examples)
99999999999999999
-[Alphabetic]---------------------------------------------------------------------
10) A(12) FieldAlphabetic yes yes
A02) A(12) FieldAlphabetic yes yes
-[Alphanumeric]-------------------------------------------------------------------
11) X(12) FieldAlphanumeric yes yes
A03) X(12) FieldAlphanumeric yes yes
-[Undefined]----------------------------------------------------------------------
12) None of the above FieldUndefined yes yes
13) S9(10)V FieldSignalNumeric1Decimals3 yes yes
999) None of the above FieldUndefined yes yes
=======================================================================================
```

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = coboljsonifier
version = 1.0.3
version = 1.0.4
description = Convert cobol copybook to Json and parse data files based on it
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
68 changes: 35 additions & 33 deletions src/coboljsonifier/extractors/field_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ class FieldExtractor(ABC):
-[Vazio]--------------------------------------------------------------
00 Empty Content Fieldempty
-[Numeric Types without signal]---------------------------------------
01) 9 - 9+ FieldSimpleNumeric
02) 9V99 - 9+V9+ FieldSimpleNumericDecimals1
03) 9V9(2) - 9+V9\([0-9]+\) FieldSimpleNumericDecimals2
04) 9(12) - 9\([0-9]+\) FieldSimpleNumeric1
05) 9(12)V99 - 9\([0-9]+\)V9+ FieldSimpleNumeric1Decimals1
06) 9(12)V9(2) - 9\([0-9]+\)V\([0-9]+\) FieldSimpleNumeric1Decimals2
01) 9 - 9+ FieldSimpleNumeric
02) 9V99 - 9+V9+ FieldSimpleNumericDecimals1
03) 9V9(2) - 9+V9\([0-9]+\) FieldSimpleNumericDecimals2
04) 9(12) - 9\([0-9]+\) FieldSimpleNumeric1
05) 9(12)V99 - 9\([0-9]+\)V9+ FieldSimpleNumeric1Decimals1
06) 9(12)V9(2) - 9\([0-9]+\)V\([0-9]+\) FieldSimpleNumeric1Decimals2
-[Numeric Types with signal]------------------------------------------
07) S9(12) - S9\([0-9]+\) FieldSignalNumeric1
08) S9(12)V99 - S9\([0-9]+\)V9+ FieldSignalNumeric1Decimals1
09) S9(12)V9(2) - S9\([0-9]+\)V\([0-9]+\) FieldSignalNumeric1Decimals2
07) S9(12) - S9\([0-9]+\) FieldSignalNumeric1
08) S9(12)V99 - S9\([0-9]+\)V9+ FieldSignalNumeric1Decimals1
09) S9(12)V9(2) - S9\([0-9]+\)V\([0-9]+\) FieldSignalNumeric1Decimals2
10) S9(10)V - S9\(([0-9]+)\)V$ FieldSignalNumeric1Decimals3
-[Masked Numeric Types]-----------------------------------------------
A1)-- +99999999999999.99 [\+|\-]?[9|Z]+\.?[9|Z]*
- +99999999999999 FieldNumericMasked1
- +ZZZZZZZZZZZZZ9.99
- ZZZZZZZZZZZZZZ.ZZ
- 99999999999999999
A01) +99999999999999.99 [\+|\-]?[9|Z]+\.?[9|Z]*
+99999999999999 FieldNumericMasked1
+ZZZZZZZZZZZZZ9.99
ZZZZZZZZZZZZZZ.ZZ
99999999999999999
-[Alphabetic]---------------------------------------------------------
A2) S9(10)V FieldSignalNumeric1Decimals3
10) A(12) - A\([0-9]+\) FieldAlphabetic
A02) A(12) - A\([0-9]+\) FieldAlphabetic
-[Alphanumeric]-------------------------------------------------------
11) X(12) - X\([0-9]+\) FieldAlphanumeric
A03) X(12) - X\([0-9]+\) FieldAlphanumeric
-[Undefined]---------------------------------------------------------
12) None of the above FieldUndefined
999) None of the above FieldUndefined
===========================================================================
'''
Expand Down Expand Up @@ -207,7 +207,19 @@ def extract(self, book_item: BookItem):
else:
return super().extract(book_item)

# A1
# 10
class FieldSignalNumeric1Decimals3(AbstractFieldExtractor):
def extract(self, book_item: BookItem):
m = re.search(r"^S9\(([0-9]+)\)V$", book_item.format)
if m:
book_item.type = "NUMERIC"
book_item.size = int(m.group(1))
book_item.decimals = 0
return book_item
else:
return super().extract(book_item)

# A01
class FieldNumericMasked1(AbstractFieldExtractor):
def extract(self, book_item: BookItem):

Expand All @@ -224,19 +236,9 @@ def extract(self, book_item: BookItem):
else:
return super().extract(book_item)

# A2
class FieldSignalNumeric1Decimals3(AbstractFieldExtractor):
def extract(self, book_item: BookItem):
m = re.search(r"^S9\(([0-9]+)\)V$", book_item.format)
if m:
book_item.type = "NUMERIC"
book_item.size = int(m.group(1))
book_item.decimals = 0
return book_item
else:
return super().extract(book_item)

# 10

# A02
class FieldAlphabetic(AbstractFieldExtractor):
def extract(self, book_item: BookItem):
m = re.search(r"^A\(([0-9]+)\)$", book_item.format)
Expand All @@ -249,7 +251,7 @@ def extract(self, book_item: BookItem):
return super().extract(book_item)


# 11
# A03
class FieldAlphanumeric(AbstractFieldExtractor):
def extract(self, book_item: BookItem):
m = re.search(r"^X\(([0-9]+)\)$", book_item.format)
Expand All @@ -261,7 +263,7 @@ def extract(self, book_item: BookItem):
else:
return super().extract(book_item)

# 12
# 999
class FieldUndefined(AbstractFieldExtractor):
def extract(self, book_item: BookItem):
raise Exception(f"ERRO ao processar field \n\t==> [{book_item.format}]")
37 changes: 19 additions & 18 deletions tests/extractors/test_field_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ class TestFieldExtractor(unittest.TestCase):
signal_numeric1_decimals2.name = "BOOK-SIGNAL-NUMERIC1-DECIMALS2"
signal_numeric1_decimals2.format = "S9(3)V9(2)"

# A1
signal_numeric_masked1 = BookItem( )
signal_numeric_masked1.type = "NUMERIC"
signal_numeric_masked1.level = "3"
signal_numeric_masked1.name = "BOOK-SIGNAL-NUMERIC-MASKED1"
signal_numeric_masked1.format = "+99999999999999.99"

# A2
# 10
simple_numeric1_decimals3 = BookItem( )
simple_numeric1_decimals3.type = "NUMERIC"
simple_numeric1_decimals3.level = "3"
simple_numeric1_decimals3.name = "BOOK-SIMPLE-NUMERIC1-DECIMALS2"
simple_numeric1_decimals3.format = "9(10)V"

# 10
# A01
signal_numeric_masked1 = BookItem( )
signal_numeric_masked1.type = "NUMERIC"
signal_numeric_masked1.level = "3"
signal_numeric_masked1.name = "BOOK-SIGNAL-NUMERIC-MASKED1"
signal_numeric_masked1.format = "+99999999999999.99"

# A02
alphabetic = BookItem( )
alphabetic.type = "NUMERIC"
alphabetic.level = "3"
alphabetic.name = "BOOK-ALPHABETIC"
alphabetic.format = "A(12)"

# 11
# A03
alphanumeric = BookItem( )
alphanumeric.type = "NUMERIC"
alphanumeric.level = "3"
Expand Down Expand Up @@ -109,27 +109,28 @@ def test_field_signal_numeric1_decimals2(self):
self.assertEqual(FieldSignalNumeric1Decimals2().extract(self.signal_numeric1_decimals2).size, 5)
self.assertEqual(FieldSignalNumeric1Decimals2().extract(self.signal_numeric1_decimals2).decimals, 2)

# A1
# 10
def test_field_signal_numeric1_decimals3(self):
self.assertEqual(FieldSignalNumeric1Decimals3().extract(self.signal_numeric1_decimals3).size, 10)
self.assertEqual(FieldSignalNumeric1Decimals3().extract(self.signal_numeric1_decimals3).decimals, 3)

# A01
def test_field_numeric_masked1(self):
self.assertEqual(FieldNumericMasked1().extract(self.signal_numeric_masked1).size, 18)
self.assertEqual(FieldNumericMasked1().extract(self.signal_numeric_masked1).decimals, 2)

# A2
def test_field_signal_numeric1_decimals3(self):
self.assertEqual(FieldSignalNumeric1Decimals3().extract(self.signal_numeric1_decimals3).size, 10)
self.assertEqual(FieldSignalNumeric1Decimals3().extract(self.signal_numeric1_decimals3).decimals, 3)

# 10
# A02
def test_field_alphabetic(self):
self.assertEqual(FieldAlphabetic().extract(self.alphabetic).size, 12)
self.assertEqual(FieldAlphabetic().extract(self.alphabetic).decimals, 0)

# 11
# A03
def test_field_alphanumeric(self):
self.assertEqual(FieldAlphanumeric().extract(self.alphanumeric).size, 12)
self.assertEqual(FieldAlphanumeric().extract(self.alphanumeric).decimals, 0)

# 12
# 999
def test_field_undefined(self):
self.assertRaises(Exception, FieldUndefined().extract, self.bookitem_empty)

Expand Down

0 comments on commit 1070fd0

Please sign in to comment.