forked from Ravf95/ddjj
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Ravf95/feature/local_mode-parserengine
new extractions and tests cases
- Loading branch information
Showing
11 changed files
with
947 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.