x12-lite 0.2.1 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc20057cae8a3440501a5a77e34a4087335c3f6801b081d81033e297f031b9a0
4
- data.tar.gz: 3e227172ccf4a107359ed4929e9aa1f8d8b72f45dc8b9672ef0900615b915b72
3
+ metadata.gz: 52b48b455f3607ad7b3deef332c22b8c7d1840177feac0937aa56225741fbc9c
4
+ data.tar.gz: e8e4a308eb587b706cee710cd18ab9ba2ca46948e3d7836621257455cd06ce46
5
5
  SHA512:
6
- metadata.gz: 0c0546d641a20c06efef4f627dacf49bb0f9b557bf20b0fa541ce85b8f4df64a217c2cd91a9812956a589ba3485cfc4a9a80caaba136fd3e65cc9ef1b0491555
7
- data.tar.gz: 6e65cc7e3e0bff3df866002473947d8b95b122ead6d59d765ee3c982c7f04d52c8fa963dbeb6dbbc243bc945123ca96d29759d9c2fec09a673259d39e1875fcd
6
+ metadata.gz: 737885ebe9240efa6728ccecaec31b27253e823872d6cec08bec933dd4757efa3951af9423546d24bf9bae2bebb7d1ce9cf383babc4a415496e6548189535cd3
7
+ data.tar.gz: ce07efaf033c829ce0ba0020875f936cef3b75ca37bfe79a4b8e483d62cc1834c0c9f98ce35bffb767c4f8e98b480ea4442996461d91f392d99caf05e6537fec
data/bin/x12 ADDED
@@ -0,0 +1,145 @@
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 "-v", "--version" , "Show version" do abort "v#{::X12::VERSION}"; end
44
+ # on "-w", "--width <width>", "Width of segment names", Integer
45
+
46
+ Kernel.abort to_s if ARGV.empty?
47
+ self
48
+ end.parse!(into: opts) rescue abort($!.message)
49
+
50
+ opts.transform_keys!(&:to_s) # stringify keys
51
+
52
+ require "time" if opts["after"]
53
+
54
+ time = Time.parse(opts["after"]) if opts["after"]
55
+ dive = opts["dive"]
56
+ # only = opts["fields-only"] and opts["fields"] = true
57
+ # quer = opts["query"].split(',').map(&:strip) if opts["query"]
58
+ # from = quer.delete("-") if quer.is_a?(Array)
59
+ # delm = opts["tsv"] ? "\t" : (opts["delim"] || "|")
60
+ # delm = {"\\n" => "\n", "\\t" => "\t"}[delm] || delm
61
+
62
+ args = []
63
+ # args << :deep if opts["repeats"]
64
+ args << :down if opts["lower"]
65
+ args << :full if opts["message"] || opts.empty?
66
+ # args << :hide if !opts["fields"]
67
+ # args << :only if only
68
+ # args << (opts["width"].to_i.between?(1, 50) ? opts["width"].to_i : 12) if opts["width"]
69
+
70
+ msgs = 0
71
+
72
+ list = []
73
+ ARGV.push(".") if dive && ARGV.empty?
74
+ ARGV.each do |path|
75
+ if File.directory?(path)
76
+ ours = []
77
+ if dive
78
+ Find.find(path) do |item|
79
+ if File.file?(item)
80
+ if time
81
+ ours << item if File.mtime(item) > time
82
+ else
83
+ ours << item
84
+ end
85
+ end
86
+ end
87
+ else
88
+ Dir[File.join(path, "*")].each do |item|
89
+ if File.file?(item)
90
+ if time
91
+ ours << item if File.mtime(item) > time
92
+ else
93
+ ours << item
94
+ end
95
+ end
96
+ end
97
+ end
98
+ list.concat(ours.sort!)
99
+ elsif File.file?(path)
100
+ if time
101
+ list << path if File.mtime(path) > time
102
+ else
103
+ list << path
104
+ end
105
+ else
106
+ warn "WARNING: unknown item in list: #{path.inspect}"
107
+ next
108
+ end
109
+ end
110
+
111
+ list.each do |file|
112
+ puts if opts["spacer"] && msgs > 0
113
+ if opts["path"]
114
+ # if quer && quer.size == 1
115
+ # print "#{file}:"
116
+ # else
117
+ puts "\n==[ #{file} ]==\n\n"
118
+ # end
119
+ end
120
+
121
+ begin
122
+ str = File.open(file, "r:bom|utf-8", &:read) rescue abort("ERROR: unable to read file: \"#{file}\"")
123
+ begin
124
+ x12 = X12.new(str)
125
+ rescue
126
+ abort "ERROR: malformed X12 file: \"#{file}\" (#{$!})" unless opts["ignore"]
127
+ next
128
+ end
129
+ # if quer
130
+ # hits = *x12.find(*quer)
131
+ # hits.unshift file if opts["path"] || from
132
+ # puts hits.join(delm)
133
+ # puts if opts["path"]
134
+ # next
135
+ # end
136
+ x12.show(*args)
137
+ msgs += 1
138
+ rescue => e
139
+ warn "WARNING: #{e.message}"
140
+ end
141
+ end
142
+
143
+ if opts["count"] && msgs > 0
144
+ puts "\nTotal messages: #{msgs}"
145
+ 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.1"
48
+ VERSION="0.3.1"
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
Binary file
data/x12-lite.gemspec CHANGED
@@ -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,25 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x12-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
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
25
+ - x12-lite-0.3.0.gem
23
26
  - x12-lite.gemspec
24
27
  homepage: https://github.com/shreeve/x12-lite
25
28
  licenses: