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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328b6d41aeeeccde646c599fbc62a8e08b5250aa
4
- data.tar.gz: f21beec92244d5731a3643b7dd07b0cc4e7b0c94
3
+ metadata.gz: a0a3cb72e76f7427fc11156441726d55d55182c6
4
+ data.tar.gz: 6c3f61b3a649318e2edc031c8ce16d183a9759b8
5
5
  SHA512:
6
- metadata.gz: 6204b8480df620b96e07967dfe18b8c64c2d6f9b3822391ab64651f7f873af2e5f8dbc4c760b7b6d80c12b4f97e778a4eec6e7adfe3152930909d0c9cdaa2362
7
- data.tar.gz: b5a7ba48f0ca141a4ee034a5ec1f97f3d62116f9f021f9468af15e7519d953f438ae6e608414d7ef025e5763aaa9d54e48b67a489a8335e2251b8aaa73f91bc1
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 Methods
15
+ ## Available Formats
16
16
 
17
- * parse_eptrn(file_path)
18
- * parse_epraw(file_path)
19
- * parse_cbnot(file_path)
20
- * parse_epa(file_path)
17
+ * eptrn
18
+ * epraw
19
+ * cbnot
20
+ * epa
21
21
 
22
- The first three methods return a readable hash in the following format:
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 method (parse_epa) returns nearly the same, but it contains nested records (according to the schema definition):
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.parse_eptrn(path_to_file, raw_values: true)
93
- Paxmex.parse_epraw(path_to_file, raw_values: true)
94
- Paxmex.parse_cbnot(path_to_file, raw_values: true)
95
- Paxmex.parse_epa(path_to_file, raw_values: true)
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.parse_eptrn('/path/to/amex/eptrn/raw/file')
113
- Paxmex.parse_epraw('/path/to/amex/epraw/raw/file')
114
- Paxmex.parse_cbnot('/path/to/amex/cbnot/raw/file')
115
- Paxmex.parse_epa('/path/to/amex/epa/raw/file')
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
@@ -1,27 +1,37 @@
1
1
  require 'paxmex/parser'
2
2
 
3
3
  module Paxmex
4
- class << self
5
- def parse_cbnot(*args)
6
- parse('cbnot', *args)
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 parse_epa(*args)
10
- parse('epa', *args)
11
+ def parse(data, opts = {})
12
+ Parser.new(data, schema_name).parse(opts)
11
13
  end
12
14
 
13
- def parse_epraw(*args)
14
- parse('epraw', *args)
15
+ def load_file(file, opts = {})
16
+ parse(File.read(file), opts)
15
17
  end
18
+ end
16
19
 
17
- def parse_eptrn(*args)
18
- parse('eptrn', *args)
20
+ class << self
21
+ def cbnot
22
+ @cbnot ||= SchemaProxy.new('cbnot')
19
23
  end
20
24
 
21
- private
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 parse(schema, *args)
24
- Parser.new(args.shift, schema).parse(*args)
33
+ def eptrn
34
+ @eptrn ||= SchemaProxy.new('eptrn')
25
35
  end
26
36
  end
27
37
  end
@@ -10,8 +10,8 @@ class Paxmex::Parser
10
10
 
11
11
  attr_reader :schema, :path
12
12
 
13
- def initialize(path, schema)
14
- @path = path
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
- @raw ||= File.read(@path).chomp
25
+ @data
26
26
  end
27
27
 
28
28
  def parse(opts = {})
29
29
  return @parsed if @parsed
30
30
 
31
- content = raw.split("\n")
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
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+ require 'time'
1
3
  require 'bigdecimal'
2
4
  require 'paxmex/schema'
3
5
 
@@ -1,3 +1,3 @@
1
1
  module Paxmex
2
- VERSION = '1.2.1'
2
+ VERSION = '2.0.0'
3
3
  end
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: 1.2.1
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-05-24 00:00:00.000000000 Z
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: '2.12'
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: '2.12'
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.5.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.