nacha 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/exe/nacha +74 -0
- data/lib/nacha/field.rb +14 -0
- data/lib/nacha/parser.rb +2 -6
- data/lib/nacha/record/base.rb +10 -0
- data/lib/nacha/version.rb +1 -1
- data/templates/html_postamble.html +1 -0
- data/templates/html_preamble.html +68 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d958fcc8edde96b13f6545611fb4fc86a751f4945955fe2f4960344bacc1ff
|
4
|
+
data.tar.gz: 6b9cbe9d4d61638f847595d76316b78263bf7b807ef1ed6c78f11e66348c7bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d559ecb5008d9e71e5c958dbc3400d35da7247c2a3f85f727adf50be020ac56c6b0ca30d470eff1247f45df05e94a603bc0754192ed7fc0baeee937abcd32ee
|
7
|
+
data.tar.gz: 718bebf3b746d052cfa2ad0c4e3390b1fef291dd16a588f25e493b1ef9f336c97ad4392951e6fe743aa5e4085430bed2b649940f7c2770733abc31c4f70b3c1e
|
data/README.md
CHANGED
data/exe/nacha
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'nacha' # Assuming this loads the Nacha gem
|
5
|
+
|
6
|
+
module Nacha
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
TEMPLATES_DIR = File.join(Gem::Specification.find_by_name("nacha").gem_dir,
|
10
|
+
"templates").freeze
|
11
|
+
|
12
|
+
HTML_PREAMBLE_FILE = File.join(TEMPLATES_DIR, "html_preamble.html")
|
13
|
+
HTML_POSTAMBLE_FILE = File.join(TEMPLATES_DIR, "html_postamble.html")
|
14
|
+
|
15
|
+
desc "parse FILE", "Parse an ACH file"
|
16
|
+
def parse(file_path)
|
17
|
+
begin
|
18
|
+
unless File.exist?(file_path)
|
19
|
+
puts "Error: File not found at #{file_path}"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
ach_file = [Nacha.parse(File.open(file_path)).first] # Use Nacha.parse
|
24
|
+
|
25
|
+
# TODO: Determine a user-friendly way to output the parsed data.
|
26
|
+
# For now, let's print the records.
|
27
|
+
if ach_file && ach_file.is_a?(Array) && !ach_file.empty?
|
28
|
+
output_html(file_path, ach_file)
|
29
|
+
else
|
30
|
+
puts "Could not parse the file or the file was empty."
|
31
|
+
end
|
32
|
+
rescue StandardError => e
|
33
|
+
puts "An error occurred during parsing: #{e.message}"
|
34
|
+
puts e.backtrace.join("\n")
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def output_html(file_path, ach_file)
|
42
|
+
puts html_preamble
|
43
|
+
puts "<h1>Successfully parsed #{file_path}</h1>\n"
|
44
|
+
display_child(0, ach_file.first, 0) # Display the first record
|
45
|
+
puts html_postamble
|
46
|
+
end
|
47
|
+
|
48
|
+
def html_preamble
|
49
|
+
@html_preamble ||= File.read(HTML_PREAMBLE_FILE)
|
50
|
+
end
|
51
|
+
|
52
|
+
def html_postamble
|
53
|
+
@html_postamble ||= File.read(HTML_POSTAMBLE_FILE)
|
54
|
+
end
|
55
|
+
|
56
|
+
def display_child(level, record, index)
|
57
|
+
# Attempt to call a summary or to_s method if it exists,
|
58
|
+
# otherwise inspect the record.
|
59
|
+
level_indent = ' ' * level.to_i
|
60
|
+
puts "<html>"
|
61
|
+
puts record.to_html
|
62
|
+
if record.respond_to?(:children) && record.children.any?
|
63
|
+
if record.children.any?
|
64
|
+
record.children.each_with_index do |child_record, child_index|
|
65
|
+
display_child(level + 1, child_record, child_index)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
puts "</html>"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Nacha::CLI.start(ARGV)
|
data/lib/nacha/field.rb
CHANGED
@@ -126,6 +126,20 @@ class Nacha::Field
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
def human_name
|
130
|
+
# @human_name ||= @name.to_s.gsub('_', ' ').capitalize
|
131
|
+
@human_name ||= @name.to_s.split('_').map(&:capitalize).join(' ')
|
132
|
+
end
|
133
|
+
|
134
|
+
def to_html
|
135
|
+
tooltip_text = "<span class=\"tooltiptext\" >#{human_name}</span>"
|
136
|
+
field_classes = "nacha-field tooltip data-field-name=\"#{@name}\""
|
137
|
+
ach_string = to_ach.gsub(' ', ' ')
|
138
|
+
"<span class=\"#{field_classes}\" data-name=\"#{@name}\">#{ach_string}" +
|
139
|
+
tooltip_text.to_s +
|
140
|
+
"</span>"
|
141
|
+
end
|
142
|
+
|
129
143
|
def to_s
|
130
144
|
@data.send(*output_conversion).to_s
|
131
145
|
end
|
data/lib/nacha/parser.rb
CHANGED
@@ -11,12 +11,7 @@ class Nacha::Parser
|
|
11
11
|
def reset!; end
|
12
12
|
|
13
13
|
def parse_file(file)
|
14
|
-
|
15
|
-
records = []
|
16
|
-
File.foreach(file).with_index do |line, line_num|
|
17
|
-
records << process(line, line_num, records.last)
|
18
|
-
parent = records.last if records.lasts.class.child_record_types.any?
|
19
|
-
end
|
14
|
+
parse_string(file.read)
|
20
15
|
end
|
21
16
|
|
22
17
|
def parse_string(str)
|
@@ -41,6 +36,7 @@ class Nacha::Parser
|
|
41
36
|
parent = parent.parent
|
42
37
|
record_types = valid_record_types(parent)
|
43
38
|
end
|
39
|
+
record.line_number = line_num if record
|
44
40
|
add_child(parent, record)
|
45
41
|
record
|
46
42
|
end
|
data/lib/nacha/record/base.rb
CHANGED
@@ -11,6 +11,7 @@ module Nacha
|
|
11
11
|
|
12
12
|
attr_accessor :children, :parent, :fields
|
13
13
|
attr_reader :name, :validations
|
14
|
+
attr_accessor :line_number
|
14
15
|
|
15
16
|
def initialize(opts = {})
|
16
17
|
@children = []
|
@@ -53,6 +54,15 @@ module Nacha
|
|
53
54
|
end.join
|
54
55
|
end
|
55
56
|
|
57
|
+
def to_html
|
58
|
+
"<div style=\"font-family: monospace;\"class='nacha-record tooltip #{record_type}'>" +
|
59
|
+
"<span class='tooltiptext'>#{record_type}</span>" +
|
60
|
+
"<span class='nacha-field' data-name='record-number'>#{"%05d" % [line_number]} | </span>" +
|
61
|
+
@fields.keys.collect do |key|
|
62
|
+
@fields[key].to_html
|
63
|
+
end.join + "</div>"
|
64
|
+
end
|
65
|
+
|
56
66
|
def inspect
|
57
67
|
"#<#{self.class.name}> #{to_h}"
|
58
68
|
end
|
data/lib/nacha/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
</body></html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<meta charset='UTF-8'>
|
5
|
+
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
6
|
+
<title>NACHA File Parser</title>
|
7
|
+
|
8
|
+
<style>
|
9
|
+
body {
|
10
|
+
font-family: Arial, sans-serif;
|
11
|
+
}
|
12
|
+
body, h1, h2, h3, p {
|
13
|
+
margin: 0;
|
14
|
+
padding: 0;
|
15
|
+
}
|
16
|
+
body {
|
17
|
+
padding: 20px;
|
18
|
+
}
|
19
|
+
h1 {
|
20
|
+
|
21
|
+
font-size: 24px;
|
22
|
+
margin-bottom: 20px;
|
23
|
+
}
|
24
|
+
|
25
|
+
span.nacha-field:hover {
|
26
|
+
background-color: yellow;
|
27
|
+
}
|
28
|
+
|
29
|
+
.tooltip {
|
30
|
+
position: relative;
|
31
|
+
display: inline-block;
|
32
|
+
/* border-bottom: 1px dotted black; *//* If you want dots under the hoverable text */
|
33
|
+
}
|
34
|
+
|
35
|
+
/* Tooltip text */
|
36
|
+
.tooltip > .tooltiptext {
|
37
|
+
visibility: hidden;
|
38
|
+
/* width: 120px; */
|
39
|
+
background-color: black;
|
40
|
+
color: #fff;
|
41
|
+
text-align: center;
|
42
|
+
padding: 5px 5px;
|
43
|
+
border-radius: 6px;
|
44
|
+
|
45
|
+
top: 100%;
|
46
|
+
left: 50%;
|
47
|
+
|
48
|
+
/* Position the tooltip text - see examples below! */
|
49
|
+
position: absolute;
|
50
|
+
z-index: 1;
|
51
|
+
}
|
52
|
+
|
53
|
+
.nacha-record > .tooltiptext {
|
54
|
+
top: -50%;
|
55
|
+
left: 100%;
|
56
|
+
background-color: gray;
|
57
|
+
}
|
58
|
+
|
59
|
+
/* Show the tooltip text when you mouse over the tooltip container */
|
60
|
+
.tooltip:hover > .tooltiptext {
|
61
|
+
visibility: visible;
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
</style>
|
66
|
+
</head>
|
67
|
+
<body>
|
68
|
+
<h1>NACHA File Parser</h1>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nacha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David H. Wilkins
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bigdecimal
|
@@ -166,7 +166,8 @@ dependencies:
|
|
166
166
|
description: Ruby parser for ACH files.
|
167
167
|
email:
|
168
168
|
- dwilkins@conecuh.com
|
169
|
-
executables:
|
169
|
+
executables:
|
170
|
+
- nacha
|
170
171
|
extensions: []
|
171
172
|
extra_rdoc_files: []
|
172
173
|
files:
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- Rakefile
|
186
187
|
- bin/console
|
187
188
|
- bin/setup
|
189
|
+
- exe/nacha
|
188
190
|
- lib/nacha.rb
|
189
191
|
- lib/nacha/aba_number.rb
|
190
192
|
- lib/nacha/ach_date.rb
|
@@ -252,6 +254,8 @@ files:
|
|
252
254
|
- lib/nacha/record/xck_entry_detail.rb
|
253
255
|
- lib/nacha/version.rb
|
254
256
|
- nacha.gemspec
|
257
|
+
- templates/html_postamble.html
|
258
|
+
- templates/html_preamble.html
|
255
259
|
homepage: https://github.com/dwilkins/nacha
|
256
260
|
licenses:
|
257
261
|
- MIT
|
@@ -270,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
274
|
- !ruby/object:Gem::Version
|
271
275
|
version: '0'
|
272
276
|
requirements: []
|
273
|
-
rubygems_version: 3.6.
|
277
|
+
rubygems_version: 3.6.7
|
274
278
|
specification_version: 4
|
275
279
|
summary: Ruby parser for ACH files.
|
276
280
|
test_files: []
|