Permalink
Browse files

Allow field values to be cast into native Ruby types

  • Loading branch information...
1 parent 1d7be6e commit 5e5c0faf7a5005ba47ba08bfb6997ab4a398f5ac Anthony Zacharakis committed Apr 5, 2013
View
@@ -21,24 +21,40 @@ Both methods return a readable hash in the following format:
{
"DATA_FILE_TRAILER_RECORD" => {
"DF_TRL_RECORD_TYPE" => "DFTRL",
- "DF_TRL_DATE" => "03082013",
+ "DF_TRL_DATE" => #<Date: 2013-04-05>,
"DF_TRL_TIME" => "0435",
- "DF_TRL_FILE_ID" => "000000",
- "DF_TRL_FILE_NAME" => "LUMOS LABS INC ",
+ "DF_TRL_FILE_ID" => 0,
+ "DF_TRL_FILE_NAME" => "LUMOS LABS INC",
"DF_TRL_RECIPIENT_KEY" => "00000000002754170029 0000000000",
- "DF_TRL_RECORD_COUNT" => "0000004"
+ "DF_TRL_RECORD_COUNT" => 4
},
"DATA_FILE_HEADER_RECORD" => {
"DF_HDR_RECORD_TYPE" => "DFHDR",
- "DF_HDR_DATE" => "03082013",
+ "DF_HDR_DATE" => #<Date: 2013-04-05>,
"DF_HDR_TIME" => "0435",
- "DF_HDR_FILE_ID" => "000000",
+ "DF_HDR_FILE_ID" => 0,
"DF_HDR_FILE_NAME" => "LUMOS LABS INC"
},
...
}
```
+Values are parsed from their representation into a corresponding native Ruby type:
+
+* Alphanumeric values become strings (with whitespace stripped)
+* Numeric values become Fixnums
+* Julian strings become Date objects
+* Date strings become Date objects
+* Alphanumerically represented decimals become BigDecimal objects (e.g: ```'0000000011A' -> BigDecimal.new(1.11, 7)```)
+
+If you'd like the raw values to be returned instead, you can set the ```raw_values``` option to true, e.g.:
+
+```ruby
+Paxmex.parse_eptrn(path_to_file, raw_values: true)
+Paxmex.parse_epraw(path_to_file, raw_values: true)
+```
+
+
## Example
```ruby
View
@@ -4,10 +4,12 @@ DATA_FILE_HEADER_RECORD:
RANGE: [0, 4]
- NAME: DF_HDR_DATE
RANGE: [5, 12]
+ TYPE: date
- NAME: DF_HDR_TIME
RANGE: [13, 16]
- NAME: DF_HDR_FILE_ID
RANGE: [17, 22]
+ TYPE: numeric
- NAME: DF_HDR_FILE_NAME
RANGE: [23, 42]
DETAIL_RECORD:
@@ -26,12 +28,16 @@ DETAIL_RECORD:
FIELDS:
- NAME: AMEX_PAYEE_NUMBER
RANGE: [0, 9]
+ TYPE: numeric
- NAME: AMEX_SORT_FIELD_1
RANGE: [10, 19]
+ TYPE: numeric
- NAME: AMEX_SORT_FIELD_2
RANGE: [20, 29]
+ TYPE: numeric
- NAME: PAYMENT_YEAR
RANGE: [30, 33]
+ TYPE: numeric
- NAME: PAYMENT_NUMBER
RANGE: [34, 41]
- NAME: RECORD_TYPE
@@ -40,25 +46,32 @@ DETAIL_RECORD:
RANGE: [43, 44]
- NAME: PAYMENT_DATE
RANGE: [45, 51]
+ TYPE: julian
- NAME: PAYMENT_AMOUNT
RANGE: [52, 62]
+ TYPE: decimal
- NAME: DEBIT_BALANCE_AMOUNT
RANGE: [63, 71]
+ TYPE: decimal
- NAME: ABA_BANK_NUMBER
RANGE: [72, 80]
+ TYPE: numeric
- NAME: SE_DDA_NUMBER
RANGE: [81, 97]
SUMMARY_OF_CHARGE_DETAIL_RECORD:
RECURRING: true
FIELDS:
- NAME: AMEX_PAYEE_NUMBER
RANGE: [0, 9]
+ TYPE: numeric
- NAME: AMEX_SE_NUMBER
RANGE: [10, 19]
+ TYPE: numeric
- NAME: SE_UNIT_NUMBER
RANGE: [20, 29]
- NAME: PAYMENT_YEAR
RANGE: [30, 33]
+ TYPE: numeric
- NAME: PAYMENT_NUMBER
RANGE: [34, 41]
- NAME: RECORD_TYPE
@@ -67,49 +80,66 @@ DETAIL_RECORD:
RANGE: [43, 44]
- NAME: SE_BUSINESS_DATE
RANGE: [45, 51]
+ TYPE: julian
- NAME: AMEX_PROCESS_DATE
RANGE: [52, 58]
+ TYPE: julian
- NAME: SOC_INVOICE_NUMBER
RANGE: [59, 64]
+ TYPE: numeric
- NAME: SOC_AMOUNT
RANGE: [65, 75]
+ TYPE: decimal
- NAME: DISCOUNT_AMOUNT
RANGE: [76, 84]
+ TYPE: decimal
- NAME: SERVICE_FEE_AMOUNT
RANGE: [85, 91]
+ TYPE: decimal
- NAME: OPTIMA_DIVIDEND_AMOUNT
RANGE: [92, 98]
+ TYPE: decimal
- NAME: NET_SOC_AMOUNT
RANGE: [99, 109]
+ TYPE: decimal
- NAME: DISCOUNT_RATE
RANGE: [110, 114]
+ TYPE: numeric
- NAME: SERVICE_FEE_RATE
RANGE: [115, 119]
+ TYPE: numeric
- NAME: OPTIMA_DIVIDEND_RATE
RANGE: [120, 124]
+ TYPE: numeric
- NAME: OPTIMA_GROSS_AMOUNT
RANGE: [125, 135]
+ TYPE: decimal
- NAME: OPTIMA_ROC_COUNT
RANGE: [136, 140]
- NAME: AMEX_GROSS_AMOUNT
RANGE: [141, 151]
+ TYPE: decimal
- NAME: AMEX_ROC_COUNT
RANGE: [152, 156]
- NAME: TRACKING_ID
RANGE: [157, 165]
+ TYPE: numeric
- NAME: CPC_INDICATOR
RANGE: [166, 166]
CHARGEBACK_DETAIL_RECORD:
RECURRING: true
FIELDS:
- NAME: AMEX_PAYEE_NUMBER
RANGE: [0, 9]
+ TYPE: numeric
- NAME: AMEX_SE_NUMBER
RANGE: [10, 19]
+ TYPE: numeric
- NAME: SE_UNIT_NUMBER
RANGE: [20, 29]
- NAME: PAYMENT_YEAR
RANGE: [30, 33]
+ TYPE: numeric
- NAME: PAYMENT_NUMBER
RANGE: [34, 41]
- NAME: RECORD_TYPE
@@ -118,43 +148,59 @@ DETAIL_RECORD:
RANGE: [43, 44]
- NAME: SE_BUSINESS_DATE
RANGE: [45, 51]
+ TYPE: julian
- NAME: AMEX_PROCESS_DATE
RANGE: [52, 58]
+ TYPE: julian
- NAME: SOC_INVOICE_NUMBER
RANGE: [59, 64]
+ TYPE: numeric
- NAME: SOC_AMOUNT
RANGE: [65, 75]
+ TYPE: decimal
- NAME: CHARGEBACK_AMOUNT
RANGE: [76, 84]
+ TYPE: decimal
- NAME: DISCOUNT_AMOUNT
RANGE: [85, 93]
+ TYPE: decimal
- NAME: SERVICE_FEE_AMOUNT
RANGE: [94, 100]
+ TYPE: decimal
- NAME: OPTIMA_DIVIDEND_AMOUNT
RANGE: [101, 107]
+ TYPE: decimal
- NAME: NET_CHARGEBACK_AMOUNT
RANGE: [108, 116]
+ TYPE: decimal
- NAME: DISCOUNT_RATE
RANGE: [117, 121]
+ TYPE: numeric
- NAME: SERVICE_FEE_RATE
RANGE: [122, 126]
+ TYPE: numeric
- NAME: OPTIMA_DIVIDEND_RATE
RANGE: [127, 131]
+ TYPE: numeric
- NAME: OPTIMA_GROSS_AMOUNT
RANGE: [132, 142]
+ TYPE: decimal
- NAME: CHARGEBACK_REASON
RANGE: [143, 422]
ADJUSTMENT_DETAIL_RECORD:
RECURRING: true
FIELDS:
- NAME: AMEX_PAYEE_NUMBER
RANGE: [0, 9]
+ TYPE: numeric
- NAME: AMEX_SE_NUMBER
RANGE: [10, 19]
+ TYPE: numeric
- NAME: SE_UNIT_NUMBER
RANGE: [20, 29]
- NAME: PAYMENT_YEAR
RANGE: [30, 33]
+ TYPE: numeric
- NAME: PAYMENT_NUMBER
RANGE: [34, 41]
- NAME: RECORD_TYPE
@@ -163,41 +209,56 @@ DETAIL_RECORD:
RANGE: [43, 44]
- NAME: AMEX_PROCESS_DATE
RANGE: [45, 51]
+ TYPE: julian
- NAME: ADJUSTMENT_NUMBER
RANGE: [52, 57]
+ TYPE: numeric
- NAME: ADJUSTMENT_AMOUNT
RANGE: [58, 66]
+ TYPE: decimal
- NAME: DISCOUNT_AMOUNT
RANGE: [67, 75]
+ TYPE: decimal
- NAME: SERVICE_FEE_AMOUNT
RANGE: [76, 82]
+ TYPE: decimal
- NAME: OPTIMA_DIVIDEND_AMOUNT
RANGE: [83, 89]
+ TYPE: decimal
- NAME: NET_ADJUSTMENT_AMOUNT
RANGE: [90, 98]
+ TYPE: decimal
- NAME: DISCOUNT_RATE
RANGE: [99, 103]
+ TYPE: numeric
- NAME: SERVICE_FEE_RATE
RANGE: [104, 108]
+ TYPE: numeric
- NAME: OPTIMA_DIVIDEND_RATE
RANGE: [109, 113]
+ TYPE: numeric
- NAME: OPTIMA_GROSS_AMOUNT
RANGE: [114, 124]
+ TYPE: decimal
- NAME: CARDMEMBER_NUMBER
RANGE: [125, 141]
+ TYPE: numeric
- NAME: ADJUSTMENT_REASON
RANGE: [142, 421]
OTHER_FEES_AND_REVENUES_DETAIL_RECORDS:
RECURRING: true
FIELDS:
- NAME: AMEX_PAYEE_NUMBER
RANGE: [0, 9]
+ TYPE: numeric
- NAME: AMEX_SE_NUMBER
RANGE: [10, 19]
+ TYPE: numeric
- NAME: SE_UNIT_NUMBER
RANGE: [20, 29]
- NAME: PAYMENT_YEAR
RANGE: [30, 33]
+ TYPE: numeric
- NAME: PAYMENT_NUMBER
RANGE: [34, 41]
- NAME: RECORD_TYPE
@@ -206,27 +267,33 @@ DETAIL_RECORD:
RANGE: [43, 44]
- NAME: AMEX_PROCESS_DATE
RANGE: [45, 51]
+ TYPE: julian
- NAME: ASSET_BILLING_AMOUNT
RANGE: [52, 60]
+ TYPE: decimal
- NAME: ASSET_BILLING_DESCRIPTION
RANGE: [61, 126]
- NAME: TAKE_ONE_COMMISSION_AMOUNT
RANGE: [126, 134]
+ TYPE: decimal
- NAME: TAKE_ONE_DESCRIPTION
RANGE: [135, 214]
- NAME: OTHER_FEE_AMOUNT
RANGE: [215, 223]
+ TYPE: decimal
- NAME: OTHER_FEE_DESCRIPTION
RANGE: [224, 303]
- NAME: ASSET_BILLING_TAX
RANGE: [304, 312]
+ TYPE: decimal
DATA_FILE_TRAILER_RECORD:
TRAILER: true
FIELDS:
- NAME: DF_TRL_RECORD_TYPE
RANGE: [0, 4]
- NAME: DF_TRL_DATE
RANGE: [5, 12]
+ TYPE: date
- NAME: DF_TRL_TIME
RANGE: [13, 16]
- NAME: DF_TRL_FILE_ID
@@ -237,3 +304,4 @@ DATA_FILE_TRAILER_RECORD:
RANGE: [43, 82]
- NAME: DF_TRL_RECORD_COUNT
RANGE: [83, 89]
+ TYPE: numeric
Oops, something went wrong.

2 comments on commit 5e5c0fa

azach replied Apr 5, 2013

@jianxioy now you can get rid of the parse_julian_date method

Contributor

Doppp replied Apr 5, 2013

👍

Please sign in to comment.