paxmex 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -15
- data/lib/paxmex.rb +22 -12
- data/lib/paxmex/parser.rb +4 -4
- data/lib/paxmex/schema/field.rb +2 -0
- data/lib/paxmex/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0a3cb72e76f7427fc11156441726d55d55182c6
|
4
|
+
data.tar.gz: 6c3f61b3a649318e2edc031c8ce16d183a9759b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4564018ecb0cb35450d0c17febaf730abf7eddce536aed508cb2e97e7b6c521e910a17b8c58cea4ab86229bcf831de73f9bc152ab52f9e699a7e75fe13fc529c
|
7
|
+
data.tar.gz: 15f6d8493280e49c7cba57d36da4eab84c862a9060561323240c2a106e54f550f1981b3d6364580392c3c05c64c6a864a1a035bee1668ea0f8ad3268355bebc2
|
data/README.md
CHANGED
@@ -12,14 +12,23 @@ This gem parses your Amex data files into human readable data.
|
|
12
12
|
% gem install paxmex
|
13
13
|
```
|
14
14
|
|
15
|
-
## Available
|
15
|
+
## Available Formats
|
16
16
|
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
17
|
+
* eptrn
|
18
|
+
* epraw
|
19
|
+
* cbnot
|
20
|
+
* epa
|
21
21
|
|
22
|
-
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Each report format has a corresponding method on the `Paxmex` module. Call `parse` or `load_file` on the return value to either parse data in memory or from a file:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Paxmex.eptrn.parse("...")
|
28
|
+
Paxmex.eptrn.load_file('/path/to/file.cbnot')
|
29
|
+
```
|
30
|
+
|
31
|
+
The first three report formats (i.e. eptrn, epraw, and cbnot) return a hash in the following format:
|
23
32
|
|
24
33
|
```ruby
|
25
34
|
{
|
@@ -43,7 +52,7 @@ The first three methods return a readable hash in the following format:
|
|
43
52
|
}
|
44
53
|
```
|
45
54
|
|
46
|
-
The last
|
55
|
+
The last format (epa) returns nearly the same thing, but contains nested records as indicated by the epa schema definition:
|
47
56
|
|
48
57
|
```ruby
|
49
58
|
{
|
@@ -89,15 +98,16 @@ Values are parsed from their representation into a corresponding native Ruby typ
|
|
89
98
|
If you'd like the raw values to be returned instead, you can set the ```raw_values``` option to true, e.g.:
|
90
99
|
|
91
100
|
```ruby
|
92
|
-
Paxmex.
|
93
|
-
Paxmex.
|
94
|
-
Paxmex.
|
95
|
-
Paxmex.
|
101
|
+
Paxmex.eptrn.parse(path_to_file, raw_values: true)
|
102
|
+
Paxmex.epraw.parse(path_to_file, raw_values: true)
|
103
|
+
Paxmex.cbnot.parse(path_to_file, raw_values: true)
|
104
|
+
Paxmex.epa.parse(path_to_file, raw_values: true)
|
96
105
|
```
|
97
106
|
|
98
107
|
## User-defined schema
|
99
108
|
|
100
109
|
If you need to parse a different format (i.e. not EPRAW, EPTRN, CBNOT, or EPA), write your own schema definition and use it like this:
|
110
|
+
|
101
111
|
```ruby
|
102
112
|
parser = Parser.new(path_to_raw_file, path_to_schema_file)
|
103
113
|
result = parser.parse
|
@@ -109,10 +119,10 @@ result = parser.parse
|
|
109
119
|
require 'paxmex'
|
110
120
|
|
111
121
|
# Use default schema definitions
|
112
|
-
Paxmex.
|
113
|
-
Paxmex.
|
114
|
-
Paxmex.
|
115
|
-
Paxmex.
|
122
|
+
Paxmex.eptrn.parse('/path/to/amex/eptrn/raw/file')
|
123
|
+
Paxmex.epraw.parse('/path/to/amex/epraw/raw/file')
|
124
|
+
Paxmex.cbnot.parse('/path/to/amex/cbnot/raw/file')
|
125
|
+
Paxmex.epa.parse('/path/to/amex/epa/raw/file')
|
116
126
|
|
117
127
|
# Use your own schema definition
|
118
128
|
parser = Parser.new('/path/to/raw/file', '/path/to/your/schema.yml')
|
@@ -120,6 +130,7 @@ result = parser.parse
|
|
120
130
|
```
|
121
131
|
|
122
132
|
The raw input files for either methods are data report files provided by American Express. These files are in either EPRAW, EPTRN, CBNOT, or EPA format so use the relevant method to parse them. We have provided dummy EPRAW, EPTRN, CBNOT, and EPA files in `spec/support`. Output and key-value pairs vary depending on whether you choose to parse an EPTRN, EPRAW, CBNOT, or EPA file.
|
133
|
+
|
123
134
|
If you need to parse a file in another format, you can write your own YAML schema for this purpose. We would be happy if you help us improving this project by sharing your schemas.
|
124
135
|
|
125
136
|
## Contributing
|
data/lib/paxmex.rb
CHANGED
@@ -1,27 +1,37 @@
|
|
1
1
|
require 'paxmex/parser'
|
2
2
|
|
3
3
|
module Paxmex
|
4
|
-
class
|
5
|
-
|
6
|
-
|
4
|
+
class SchemaProxy
|
5
|
+
attr_reader :schema_name
|
6
|
+
|
7
|
+
def initialize(schema_name)
|
8
|
+
@schema_name = schema_name
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
+
def parse(data, opts = {})
|
12
|
+
Parser.new(data, schema_name).parse(opts)
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
parse(
|
15
|
+
def load_file(file, opts = {})
|
16
|
+
parse(File.read(file), opts)
|
15
17
|
end
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
class << self
|
21
|
+
def cbnot
|
22
|
+
@cbnot ||= SchemaProxy.new('cbnot')
|
19
23
|
end
|
20
24
|
|
21
|
-
|
25
|
+
def epa
|
26
|
+
@epa ||= SchemaProxy.new('epa')
|
27
|
+
end
|
28
|
+
|
29
|
+
def epraw
|
30
|
+
@epraw ||= SchemaProxy.new('epraw')
|
31
|
+
end
|
22
32
|
|
23
|
-
def
|
24
|
-
|
33
|
+
def eptrn
|
34
|
+
@eptrn ||= SchemaProxy.new('eptrn')
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
data/lib/paxmex/parser.rb
CHANGED
@@ -10,8 +10,8 @@ class Paxmex::Parser
|
|
10
10
|
|
11
11
|
attr_reader :schema, :path
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(data, schema)
|
14
|
+
@data = data.chomp
|
15
15
|
@parent_chain = []
|
16
16
|
|
17
17
|
if File.file?(schema)
|
@@ -22,13 +22,13 @@ class Paxmex::Parser
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def raw
|
25
|
-
@
|
25
|
+
@data
|
26
26
|
end
|
27
27
|
|
28
28
|
def parse(opts = {})
|
29
29
|
return @parsed if @parsed
|
30
30
|
|
31
|
-
content =
|
31
|
+
content = @data.split("\n")
|
32
32
|
|
33
33
|
# Parse the trailing section first so that we don't need
|
34
34
|
# to consider it when parsing recurring sections
|
data/lib/paxmex/schema/field.rb
CHANGED
data/lib/paxmex/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paxmex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daryl Yeo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '3.0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '3.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.11
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: This gem parses your Amex data files into human readable data.
|