x12-lite 0 → 0.3.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/x12 +144 -0
  3. data/lib/x12-lite.rb +2 -138
  4. data/x12-lite.gemspec +2 -1
  5. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beb279f2d650c4542ef4e8d1c1c7776bd186f60fa68285b7b3cdba327b8dda6f
4
- data.tar.gz: 68a9267df83e0a11f3f27aafde4d6215e710d758a15b80ff37ddf3db0674f8ee
3
+ metadata.gz: 903651692110af8d1a21b2203fbf64dc2e37611dedc302de5566e9a7c6637f53
4
+ data.tar.gz: 2e34a7c8eb3f0fcf8d91ae7ada686d8aacd46ebdb6985d68ad73faca7285d442
5
5
  SHA512:
6
- metadata.gz: b781293ca7d307daa74db041c84beed21cd73db1ed9890674611c3ed6997d34f05e196a0d7f96d281ee65016b6526302f0de1e1ac59629548fe7bf16b50eddb8
7
- data.tar.gz: 61dcd151d94c6e109e10a1053038a21ac5801b896035e951e88d6a0096ed0a29e4ee96c5b9ba94863c2182231d0c24512076bcc5c6f500d28fd3849449a12e85
6
+ metadata.gz: b6d08153aa69ec9a5a205575729647e4aaffaf1948691a69e2202f5c54966be72ba6564ad9bae631041fc17f7a0a047894023bcb91d08f1ed3a88219b0ca9ee4
7
+ data.tar.gz: 87b9eacf6971b21adb5b397e2b89876e544c74ed30d0177879e51bbf563fddcf91bb49410af2779d746fe3c0d8c248eb77dcc5c127f0dc061dc543e959f6ec2f
data/bin/x12 ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # ==============================================================================
4
+ # x12-lite.rb: X12 command line utility
5
+ #
6
+ # Author: Steve Shreeve <steve.shreeve@gmail.com>
7
+ # Date: October 10, 2024
8
+ #
9
+ # Legal: All rights reserved.
10
+ # ==============================================================================
11
+
12
+ require "optparse"
13
+ require "x12-lite"
14
+
15
+ trap("INT" ) { abort "\n" }
16
+ trap("PIPE") { abort "\n" } rescue nil
17
+
18
+ opts = {
19
+ # "lower" => true,
20
+ # "ignore" => true,
21
+ # "message" => true,
22
+ # "spacer" => true,
23
+ }
24
+
25
+ OptionParser.new.instance_eval do
26
+ @banner = "usage: #{program_name} [options] <file> <file> ..."
27
+
28
+ on "-a", "--after <date>" , "After (date as 'YYYYMMDD' or time as 'YYYYMMDD HHMMSS')"
29
+ on "-c", "--count" , "Count messages at the end"
30
+ on "-d", "--dive" , "Dive into directories recursively"
31
+ # on "--delim <char>" , "Delimiter to use"
32
+ # on "-f", "--fields" , "Show fields"
33
+ # on "-F", "--fields-only" , "Show fields only, not repeat indicators"
34
+ on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
35
+ on "-i", "--ignore" , "Ignore malformed X12 files"
36
+ on "-l", "--lower" , "Show segment names in lowercase"
37
+ on "-m", "--message" , "Show message body"
38
+ on "-p", "--path" , "Show path for each message"
39
+ # on "-q", "--query <value>" , "Query a specific value"
40
+ # on "-r", "--repeats" , "Show field repeats on their own line"
41
+ on "-s", "--spacer" , "Show an empty line between messages"
42
+ # on "-t", "--tsv" , "Tab-delimit output (tsv format)"
43
+ # on "-w", "--width <width>", "Width of segment names", Integer
44
+
45
+ Kernel.abort to_s if ARGV.empty?
46
+ self
47
+ end.parse!(into: opts) rescue abort($!.message)
48
+
49
+ opts.transform_keys!(&:to_s) # stringify keys
50
+
51
+ require "time" if opts["after"]
52
+
53
+ time = Time.parse(opts["after"]) if opts["after"]
54
+ dive = opts["dive"]
55
+ # only = opts["fields-only"] and opts["fields"] = true
56
+ # quer = opts["query"].split(',').map(&:strip) if opts["query"]
57
+ # from = quer.delete("-") if quer.is_a?(Array)
58
+ # delm = opts["tsv"] ? "\t" : (opts["delim"] || "|")
59
+ # delm = {"\\n" => "\n", "\\t" => "\t"}[delm] || delm
60
+
61
+ args = []
62
+ # args << :deep if opts["repeats"]
63
+ args << :down if opts["lower"]
64
+ args << :full if opts["message"] || opts.empty?
65
+ # args << :hide if !opts["fields"]
66
+ # args << :only if only
67
+ # args << (opts["width"].to_i.between?(1, 50) ? opts["width"].to_i : 12) if opts["width"]
68
+
69
+ msgs = 0
70
+
71
+ list = []
72
+ ARGV.push(".") if dive && ARGV.empty?
73
+ ARGV.each do |path|
74
+ if File.directory?(path)
75
+ ours = []
76
+ if dive
77
+ Find.find(path) do |item|
78
+ if File.file?(item)
79
+ if time
80
+ ours << item if File.mtime(item) > time
81
+ else
82
+ ours << item
83
+ end
84
+ end
85
+ end
86
+ else
87
+ Dir[File.join(path, "*")].each do |item|
88
+ if File.file?(item)
89
+ if time
90
+ ours << item if File.mtime(item) > time
91
+ else
92
+ ours << item
93
+ end
94
+ end
95
+ end
96
+ end
97
+ list.concat(ours.sort!)
98
+ elsif File.file?(path)
99
+ if time
100
+ list << path if File.mtime(path) > time
101
+ else
102
+ list << path
103
+ end
104
+ else
105
+ warn "WARNING: unknown item in list: #{path.inspect}"
106
+ next
107
+ end
108
+ end
109
+
110
+ list.each do |file|
111
+ puts if opts["spacer"] && msgs > 0
112
+ if opts["path"]
113
+ # if quer && quer.size == 1
114
+ # print "#{file}:"
115
+ # else
116
+ puts "\n==[ #{file} ]==\n\n"
117
+ # end
118
+ end
119
+
120
+ begin
121
+ str = File.open(file, "r:bom|utf-8", &:read) rescue abort("ERROR: unable to read file: \"#{file}\"")
122
+ begin
123
+ x12 = X12.new(str)
124
+ rescue
125
+ abort "ERROR: malformed X12 file: \"#{file}\" (#{$!})" unless opts["ignore"]
126
+ next
127
+ end
128
+ # if quer
129
+ # hits = *x12.find(*quer)
130
+ # hits.unshift file if opts["path"] || from
131
+ # puts hits.join(delm)
132
+ # puts if opts["path"]
133
+ # next
134
+ # end
135
+ x12.show(*args)
136
+ msgs += 1
137
+ rescue => e
138
+ warn "WARNING: #{e.message}"
139
+ end
140
+ end
141
+
142
+ if opts["count"] && msgs > 0
143
+ puts "\nTotal messages: #{msgs}"
144
+ end
data/lib/x12-lite.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # ==============================================================================
4
4
  # x12-lite.rb: X12 library for Ruby
5
5
  #
6
- # Author: Steve Shreeve <steve.shreeve@trusthealth.com>
6
+ # Author: Steve Shreeve <steve.shreeve@gmail.com>
7
7
  # Date: October 7, 2024
8
8
  #
9
9
  # Legal: All rights reserved.
@@ -45,7 +45,7 @@ end
45
45
  # ==[ X12 ]=====================================================================
46
46
 
47
47
  class X12
48
- VERSION="0.2.0"
48
+ VERSION="0.3.0"
49
49
 
50
50
  include Enumerable
51
51
 
@@ -602,142 +602,6 @@ class X12
602
602
  # end
603
603
  end
604
604
 
605
- if __FILE__ == $0
606
-
607
- require "optparse"
608
-
609
- trap("INT" ) { abort "\n" }
610
- trap("PIPE") { abort "\n" } rescue nil
611
-
612
- opts = {
613
- # "lower" => true,
614
- # "ignore" => true,
615
- # "message" => true,
616
- # "spacer" => true,
617
- }
618
-
619
- OptionParser.new.instance_eval do
620
- @banner = "usage: #{program_name} [options] <file> <file> ..."
621
-
622
- on "-a", "--after <date>" , "After (date as 'YYYYMMDD' or time as 'YYYYMMDD HHMMSS')"
623
- on "-c", "--count" , "Count messages at the end"
624
- on "-d", "--dive" , "Dive into directories recursively"
625
- # on "--delim <char>" , "Delimiter to use"
626
- # on "-f", "--fields" , "Show fields"
627
- # on "-F", "--fields-only" , "Show fields only, not repeat indicators"
628
- on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
629
- on "-i", "--ignore" , "Ignore malformed X12 files"
630
- on "-l", "--lower" , "Show segment names in lowercase"
631
- on "-m", "--message" , "Show message body"
632
- on "-p", "--path" , "Show path for each message"
633
- # on "-q", "--query <value>" , "Query a specific value"
634
- # on "-r", "--repeats" , "Show field repeats on their own line"
635
- on "-s", "--spacer" , "Show an empty line between messages"
636
- # on "-t", "--tsv" , "Tab-delimit output (tsv format)"
637
- # on "-w", "--width <width>", "Width of segment names", Integer
638
-
639
- Kernel.abort to_s if ARGV.empty?
640
- self
641
- end.parse!(into: opts) rescue abort($!.message)
642
-
643
- opts.transform_keys!(&:to_s) # stringify keys
644
-
645
- require "time" if opts["after"]
646
-
647
- time = Time.parse(opts["after"]) if opts["after"]
648
- dive = opts["dive"]
649
- # only = opts["fields-only"] and opts["fields"] = true
650
- # quer = opts["query"].split(',').map(&:strip) if opts["query"]
651
- # from = quer.delete("-") if quer.is_a?(Array)
652
- # delm = opts["tsv"] ? "\t" : (opts["delim"] || "|")
653
- # delm = {"\\n" => "\n", "\\t" => "\t"}[delm] || delm
654
-
655
- args = []
656
- # args << :deep if opts["repeats"]
657
- args << :down if opts["lower"]
658
- args << :full if opts["message"] || opts.empty?
659
- # args << :hide if !opts["fields"]
660
- # args << :only if only
661
- # args << (opts["width"].to_i.between?(1, 50) ? opts["width"].to_i : 12) if opts["width"]
662
-
663
- msgs = 0
664
-
665
- list = []
666
- ARGV.push(".") if dive && ARGV.empty?
667
- ARGV.each do |path|
668
- if File.directory?(path)
669
- ours = []
670
- if dive
671
- Find.find(path) do |item|
672
- if File.file?(item)
673
- if time
674
- ours << item if File.mtime(item) > time
675
- else
676
- ours << item
677
- end
678
- end
679
- end
680
- else
681
- Dir[File.join(path, "*")].each do |item|
682
- if File.file?(item)
683
- if time
684
- ours << item if File.mtime(item) > time
685
- else
686
- ours << item
687
- end
688
- end
689
- end
690
- end
691
- list.concat(ours.sort!)
692
- elsif File.file?(path)
693
- if time
694
- list << path if File.mtime(path) > time
695
- else
696
- list << path
697
- end
698
- else
699
- warn "WARNING: unknown item in list: #{path.inspect}"
700
- next
701
- end
702
- end
703
-
704
- list.each do |file|
705
- puts if opts["spacer"] && msgs > 0
706
- if opts["path"]
707
- # if quer && quer.size == 1
708
- # print "#{file}:"
709
- # else
710
- puts "\n==[ #{file} ]==\n\n"
711
- # end
712
- end
713
-
714
- begin
715
- str = File.open(file, "r:bom|utf-8", &:read) rescue abort("ERROR: unable to read file: \"#{file}\"")
716
- begin
717
- x12 = X12.new(str)
718
- rescue
719
- abort "ERROR: malformed X12 file: \"#{file}\" (#{$!})" unless opts["ignore"]
720
- next
721
- end
722
- # if quer
723
- # hits = *x12.find(*quer)
724
- # hits.unshift file if opts["path"] || from
725
- # puts hits.join(delm)
726
- # puts if opts["path"]
727
- # next
728
- # end
729
- x12.show(*args)
730
- msgs += 1
731
- rescue => e
732
- warn "WARNING: #{e.message}"
733
- end
734
- end
735
-
736
- if opts["count"] && msgs > 0
737
- puts "\nTotal messages: #{msgs}"
738
- end
739
- end
740
-
741
605
  __END__
742
606
 
743
607
  x12 = X12.new
data/x12-lite.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "x12-lite"
5
- s.version = `grep -m 1 '^\s*VERSION' lib/x12.rb | head -1 | cut -f 2 -d '"'`
5
+ s.version = `grep -m 1 '^\s*VERSION' lib/x12-lite.rb | head -1 | cut -f 2 -d '"'`
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary = "A " +
@@ -11,5 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.license = "MIT"
12
12
  s.platform = Gem::Platform::RUBY
13
13
  s.files = `git ls-files`.split("\n") - %w[.gitignore]
14
+ s.executables = `cd bin && git ls-files .`.split("\n")
14
15
  s.required_ruby_version = Gem::Requirement.new(">= 3.0") if s.respond_to? :required_ruby_version=
15
16
  end
metadata CHANGED
@@ -1,24 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x12-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: '0'
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-07 00:00:00.000000000 Z
11
+ date: 2024-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem to parse and generate X.12 transactions
14
14
  email: steve.shreeve@gmail.com
15
- executables: []
15
+ executables:
16
+ - x12
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
20
  - Gemfile
20
21
  - LICENSE
21
22
  - README.md
23
+ - bin/x12
22
24
  - lib/x12-lite.rb
23
25
  - x12-lite.gemspec
24
26
  homepage: https://github.com/shreeve/x12-lite