Skip to content

Commit

Permalink
Merge pull request #5 from Ravf95/feature/local_mode-parserengine
Browse files Browse the repository at this point in the history
new extractions and tests cases
  • Loading branch information
aVolpe authored Feb 20, 2021
2 parents 4abb642 + c5aea0e commit 3273701
Show file tree
Hide file tree
Showing 11 changed files with 947 additions and 175 deletions.
11 changes: 9 additions & 2 deletions parser/declaration/declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ type Declaration struct {
Cedula int `json:"cedula"`
Nombre string `json:"nombre"`
Apellido string `json:"apellido"`
Cargo string `json:"cargo"`
Institucion string `json:"institucion"`

Conyuge string `json:"conyuge"`

Instituciones []*Job `json:"instituciones"`

// Activos
Deposits []*Deposit `json:"depositos"`
Expand All @@ -36,6 +38,11 @@ type Declaration struct {
Resumen *Summary `json:"resumen"`
}

type Job struct {
Cargo string `json:"cargo"`
Institucion string `json:"institucion"`
}

type Summary struct {
TotalActivo int64 `json:"totalActivo"`
TotalPasivo int64 `json:"totalPasivo"`
Expand Down
69 changes: 42 additions & 27 deletions parser/extract/basics.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,82 @@
package extract

import (
"bufio"
"github.com/pkg/errors"
"time"
)

// Date returns the date for the declaration.
func Date(scanner *bufio.Scanner) (time.Time, error) {
date := getString(scanner, "DECLARACIÓN", EVdate, nil)
func Date(e *Extractor) (time.Time, error) {
var date string

e.BindFlag(EXTRACTOR_FLAG_1)
if e.MoveUntilContains(CurrToken, "DECLARACIÓN") {
for e.Scan() {
if isDate(e.CurrToken) {
date = e.CurrToken
break
}
}
}

if date == "" {
return time.Time{}, errors.New("Failed when extracting date")
return time.Time{}, errors.New("failed when extracting date")
}

t, err := time.Parse("02/01/2006", date)
if err != nil {
return time.Time{}, errors.New("Error parsing " + date + err.Error())
}

return t, nil
}

// Cedula returns the ID card number.
func Cedula(scanner *bufio.Scanner) (int, error) {
value := getInt(scanner, "CÉDULA", EVnum, nil)
func Cedula(e *Extractor) (int, error) {
var value int

e.BindFlag(EXTRACTOR_FLAG_1)
if e.MoveUntilStartWith(CurrToken, "CÉDULA") {
if isNumber(e.NextToken) {
value = stringToInt(e.NextToken)
}
}

if value == 0 {
return 0, errors.New("failed when extracting cedula")
}
return value, nil
}

// Name returns the official's name.
func Name(scanner *bufio.Scanner) (string, error) {
value := getString(scanner, "NOMBRE", EValphaNum, nil)
func Name(e *Extractor) (string, error) {
var value string

e.BindFlag(EXTRACTOR_FLAG_1)
if e.MoveUntilStartWith(CurrToken, "NOMBRE") {
if isAlpha(e.NextToken) {
value = e.NextToken
}
}

if value == "" {
return "", errors.New("failed when extracting name")
}
return value, nil
}

// Lastname returns the official's lastname.
func Lastname(scanner *bufio.Scanner) (string, error) {
value := getString(scanner, "APELLIDOS", EValphaNum, nil)
if value == "" {
return "", errors.New("failed when extracting lastname")
}
return value, nil
}
func Lastname(e *Extractor) (string, error) {
var value string

// Institution returns the official's work place.
func Institution(scanner *bufio.Scanner) (string, error) {
value := getString(scanner, "DIRECCIÓN", EValphaNum, nil)
if value == "" {
return "", errors.New("failed when extracting institucion")
e.BindFlag(EXTRACTOR_FLAG_1)
if e.MoveUntilStartWith(CurrToken, "APELLIDOS") {
if isAlpha(e.NextToken) {
value = e.NextToken
}
}
return value, nil
}

// JobTitle returns the official's job title.
func JobTitle(scanner *bufio.Scanner) (string, error) {
value := getString(scanner, "CARGO", EValphaNum, nil)
if value == "" {
return "", errors.New("failed when extracting cargo")
return "", errors.New("failed when extracting lastname")
}
return value, nil
}
2 changes: 1 addition & 1 deletion parser/extract/debt.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func getDebt2(scanner *bufio.Scanner, values [6]string, value7 string) []*declar
counter := 0
index := 0
values, nextPage := getDebtValues(scanner, index, true)
for !isNumber(values[5]) && !nextPage {
for values[5] != "" && !isNumber(values[5]) && !nextPage {
// Shift to the right by 1 and do not get the last value since it's the
// business for the next item.
var v [6]string
Expand Down
Loading

0 comments on commit 3273701

Please sign in to comment.