tcd_x12 1.6.2 → 1.6.3

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
  SHA256:
3
- metadata.gz: d1cdb7392e9ddcc71af854524311fc27294a1ef51415f0a1491494dfde395048
4
- data.tar.gz: 28cd1f96294140ed9a2a2f5fd5009e5baab5db110cc67070ce2a5d715123bb21
3
+ metadata.gz: f7b6f52dcf0d6a34ee6992f9d310e8e9e6376ebe8e834d033467994b815d709d
4
+ data.tar.gz: c8cdc729f70ec8b5dd9014a37b09f8b80f25060f9c5fbde20cd2feb1cd7f3ec4
5
5
  SHA512:
6
- metadata.gz: 90ef90253cefad0d0e4002776e903db839fddcc7ec17f305f8bb986373895d07c4716b0a828d7143c3330e9541c1d1984dd3cc0dc7b13efacdd5a5384af9520c
7
- data.tar.gz: c703ed73f8b137f61f1f64b76ef96bf3ba468e751e103a549ccb95746dec3390f051f389df8b27488d4f7fae76880da435137478f522e4cac765d42c597fcbc4
6
+ metadata.gz: b961effa4a173323f3871df5a77f5c41a9174a658d30b2effbe5b2b97d7e43e7ec7bd8ef811c20762909cfd0b355ec213a0b19613d4d74baaaaac715a45ecccd
7
+ data.tar.gz: e249eb024b282bff8fd8c82ca18524decb81d3064fcad02ba439abe95b27da15900123b3b6e9523396d9062a6dcaa6b2b77f95e3337ea43dad4f7beaa8cd3521
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6.0
3
+
4
+ Style/Documentation:
5
+ Enabled: true
6
+ Exclude:
7
+ - 'test/**/*.rb'
8
+
9
+ Style/DocumentationMethod:
10
+ Enabled: true
11
+ Exclude:
12
+ - 'test/**/*.rb'
13
+
14
+ # Don't leave calls to pry lying around.
15
+ Lint/Debugger:
16
+ Enabled: true
17
+
18
+ Metrics/LineLength:
19
+ Max: 150
20
+
21
+ Style/StringLiterals:
22
+ EnforcedStyle: single_quotes
23
+
24
+ Style/FormatString:
25
+ EnforcedStyle: sprintf
26
+
27
+ Style/CommentedKeyword:
28
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ 11/26/19 - release 1.6.3
4
+ * Update 855.xml
5
+
3
6
  10/25/19 - release 1.6.2
4
7
  * Fix invalid yard doc comments
5
8
 
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # X12
2
2
 
3
+ [![Gem](https://img.shields.io/gem/v/tcd_x12)][gem]
3
4
  ![Ruby Version](https://img.shields.io/badge/Ruby->=1.9.1-red.svg)
4
- [![Gem Version](https://badge.fury.io/rb/tcd_x12.svg)](https://badge.fury.io/rb/tcd_x12)
5
- ![GitHub](https://img.shields.io/github/license/tcd/x12)
5
+ [![Inline docs](http://inch-ci.org/github/tcd/x12.svg?branch=master)][inch-ci]
6
+ [![License](https://img.shields.io/github/license/tcd/x12)][license]
7
+ [![Documentation](http://img.shields.io/badge/docs-rubydoc.info-blue.svg)][docs]
8
+
9
+ [gem]: https://rubygems.org/gems/tcd_x12
10
+ [inch-ci]: http://inch-ci.org/github/tcd/x12
11
+ [license]: https://github.com/tcd/x12/blob/master/LICENSE
12
+ [docs]: https://www.rubydoc.info/gems/tcd_x12/1.6.2
6
13
 
7
14
  Changes welcome, especially new document types or better tests.
8
15
 
data/Rakefile CHANGED
@@ -11,4 +11,13 @@ Rake::TestTask.new(:test) do |t|
11
11
  t.verbose = true
12
12
  end
13
13
 
14
- task :default => :test
14
+ # desc 'Test the plugin, and run benchmarks'
15
+ # Rake::TestTask.new(:benchmark) do |t|
16
+ # ENV['BENCH'] = 'true'
17
+ # t.libs << 'lib'
18
+ # t.libs << 'test'
19
+ # t.test_files = FileList['test/**/*_test.rb']
20
+ # t.verbose = true
21
+ # end
22
+
23
+ task(default: :test)
data/lib/x12/base.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  module X12
2
2
 
3
- # Base class for Segment, Composite, and Loop.
3
+ # Base class for {Segment}, {Composite}, and {Loop}.
4
4
  # Contains setable segment_separator, field_separator, and composite_separator fields.
5
5
  class Base
6
6
 
7
7
  attr_reader :name, :repeats
8
- attr_accessor :segment_separator, :field_separator, :composite_separator, :next_repeat, :parsed_str, :nodes
8
+ attr_accessor :segment_separator, :field_separator, :composite_separator
9
+ attr_accessor :next_repeat, :parsed_str, :nodes
9
10
 
10
11
  # Creates a new base element with a given name, array of sub-elements, and array of repeats if any.
12
+ #
13
+ # @return [void]
11
14
  def initialize(name, arr, repeats = nil)
12
15
  @nodes = arr
13
16
  @name = name
@@ -23,12 +26,15 @@ module X12
23
26
  end
24
27
 
25
28
  # Formats a printable string containing the base element's content.
29
+ #
26
30
  # @return [String]
27
31
  def inspect
28
32
  "#{self.class.to_s.sub(/^.*::/, '')} (#{name}) #{repeats} #{super.inspect[1..-2]} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/\\*\"/, '"')
29
33
  end
30
34
 
31
35
  # Prints a tree-like representation of the element.
36
+ #
37
+ # @return [void]
32
38
  def show(ind = '')
33
39
  count = 0
34
40
  self.to_a.each{|i|
@@ -48,8 +54,8 @@ module X12
48
54
  }
49
55
  end
50
56
 
51
- # Try to parse the current element one more time if required. Returns the rest of the string
52
- # or the same string if no more repeats are found or required.
57
+ # Try to parse the current element one more time if required.
58
+ # Returns the rest of the string or the same string if no more repeats are found or required.
53
59
  def do_repeats(s)
54
60
  if self.repeats.end > 1
55
61
  possible_repeat = self.dup
@@ -63,6 +69,8 @@ module X12
63
69
  end
64
70
 
65
71
  # Empty out the current element.
72
+ #
73
+ # @return [void]
66
74
  def set_empty!
67
75
  @next_repeat = nil
68
76
  @parsed_str = nil
@@ -170,7 +178,8 @@ module X12
170
178
  self.nodes.find{ |i| i.has_content? }
171
179
  end
172
180
 
173
- # Adds a repeat to a segment or loop. Returns a new segment/loop or self if empty.
181
+ # Adds a repeat to a segment or loop.
182
+ # Returns a new segment/loop or self if empty.
174
183
  def repeat
175
184
  res = if self.has_content? # Do not repeat an empty segment
176
185
  last_repeat = self.to_a[-1]
data/lib/x12/parser.rb CHANGED
@@ -20,8 +20,11 @@ module X12
20
20
  ].freeze
21
21
 
22
22
  # Creates a parser out of a definition.
23
+ #
24
+ # @param file_name [String]
25
+ # @return [void]
23
26
  def initialize(file_name)
24
- save_definition = @x12_definition
27
+ save_definition = @x12_definition if defined? @x12_definition
25
28
 
26
29
  # Deal with Microsoft devices
27
30
  # get the current working directory
data/lib/x12/segment.rb CHANGED
@@ -2,8 +2,13 @@ module X12
2
2
 
3
3
  # Implements a segment containing fields or composites
4
4
  class Segment < Base
5
+ attr_accessor :fields
6
+
5
7
  # Parses this segment out of a string, puts the match into value,
6
8
  # returns the rest of the string - nil if cannot parse.
9
+ #
10
+ # @param str [String]
11
+ # @return [nil]
7
12
  def parse(str)
8
13
  s = str
9
14
  # puts "Parsing segment #{name} from #{s} with regexp [#{regexp.source}]"
@@ -38,7 +43,7 @@ module X12
38
43
 
39
44
  # Returns a regexp that matches this particular segment.
40
45
  def regexp
41
- unless @regexp
46
+ unless defined? @regexp
42
47
  if self.nodes.find { |i| i.type =~ /^".+"$/ }
43
48
  # It's a very special regexp if there are constant fields
44
49
  re_str = self.nodes.inject("^#{name}#{Regexp.escape(field_separator)}") { |s, i|
@@ -68,7 +73,7 @@ module X12
68
73
  # puts field_num
69
74
 
70
75
  # Parse the segment if not parsed already
71
- unless @fields
76
+ unless defined? @fields
72
77
  @fields = self.to_s.chop.split(Regexp.new(Regexp.escape(field_separator)))
73
78
  self.nodes.each_index { |i| self.nodes[i].content = @fields[i + 1] }
74
79
  end
data/lib/x12/table.rb CHANGED
@@ -2,9 +2,11 @@ module X12
2
2
 
3
3
  # This just a named hash to store validation tables.
4
4
  class Table < Hash
5
+ # @return [String]
5
6
  attr_reader :name
6
7
 
7
8
  # Create a new table with given name and hash content.
9
+ # @return [void]
8
10
  def initialize(name, name_values)
9
11
  @name = name
10
12
  self.merge!(name_values)
data/lib/x12/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module X12
2
- VERSION = '1.6.2'.freeze
2
+ VERSION = '1.6.3'.freeze
3
3
  end
@@ -99,7 +99,7 @@ module X12
99
99
  end
100
100
 
101
101
  def parse_table(e)
102
- name, min, max, type, required, validation = parse_attributes(e)
102
+ name, _min, _max, _type, _required, _validation = parse_attributes(e)
103
103
 
104
104
  content = e.find('Entry').inject({}) { |t, entry|
105
105
  t[entry.attributes['name']] = entry.attributes['value']
@@ -109,7 +109,7 @@ module X12
109
109
  end
110
110
 
111
111
  def parse_segment(e)
112
- name, min, max, type, required, validation = parse_attributes(e)
112
+ name, min, max, _type, _required, _validation = parse_attributes(e)
113
113
 
114
114
  fields = e.find('Field').inject([]) { |f, field|
115
115
  f << parse_field(field)
@@ -118,7 +118,7 @@ module X12
118
118
  end
119
119
 
120
120
  def parse_composite(e)
121
- name, min, max, type, required, validation = parse_attributes(e)
121
+ name, _min, _max, _type, _required, _validation = parse_attributes(e)
122
122
 
123
123
  fields = e.find('Field').inject([]) { |f, field|
124
124
  f << parse_field(field)
@@ -127,7 +127,7 @@ module X12
127
127
  end
128
128
 
129
129
  def parse_loop(e)
130
- name, min, max, type, required, validation = parse_attributes(e)
130
+ name, min, max, _type, _required, _validation = parse_attributes(e)
131
131
 
132
132
  components = e.find('*').to_a.inject([]) { |r, element|
133
133
  r << case element.name
data/misc/850.xml CHANGED
@@ -1,5 +1,4 @@
1
-
2
- <!--
1
+ <!--
3
2
  (c) 2019 Clay Dunston
4
3
  The code in this file is licensed under the MIT license.
5
4
  -->
data/misc/855.xml ADDED
@@ -0,0 +1,47 @@
1
+ <!--
2
+ (c) 2019 Clay Dunston
3
+ The code in this file is licensed under the MIT license.
4
+ -->
5
+
6
+ <!--
7
+ This is an example of a message definition spread among several
8
+ files: main loop is here, all other definitions, i.e., segments,
9
+ composites, validation tables live in separate files.
10
+ -->
11
+
12
+ <Definition>
13
+ <Loop name="855" comment="">
14
+ <Segment name="ISA" max="1" required="y" />
15
+ <Segment name="GS" max="1" required="y" />
16
+
17
+ <Segment name="ST" max="1" required="y">
18
+ <Field name="TransactionSetIdentifierCode" const="855" min="3" max="3" comment="Code uniquely identifying a Transaction Set" />
19
+ <Field name="TransactionSetControlNumber" min="4" max="9" comment="Identifying control number that must be unique within the transaction set functional group assigned by the originator for a transaction set" />
20
+ </Segment>
21
+ <Segment name="BAK" max="1" required="y" />
22
+
23
+ <Loop name="L1000" max="200">
24
+ <Segment name="N1" max="1" required="n" />
25
+ <Segment name="N3" max="2" required="n" />
26
+ <Segment name="N4" min="1" required="n" />
27
+ </Loop>
28
+
29
+ <Loop name="L1010" max="100000">
30
+ <Segment name="PO1" max="1" required="y" />
31
+ <Loop name="L1020" min="1">
32
+ <Segment name="PID" max="1" required="n" />
33
+ </Loop>
34
+ <Loop name="L1030" max="104">
35
+ <Segment name="ACK" max="1" required="y" />
36
+ </Loop>
37
+ </Loop>
38
+
39
+ <Loop name="L1040" max="1">
40
+ <Segment name="CTT" max="1" required="y" />
41
+ </Loop>
42
+
43
+ <Segment name="SE" max="1" required="y" />
44
+
45
+ <Segment name="GE" max="1" required="y" />
46
+ <Segment name="IEA" max="1" required="y" />
47
+ </Definition>
data/x12.gemspec CHANGED
@@ -11,8 +11,14 @@ Gem::Specification.new do |gem|
11
11
  gem.summary = 'A gem to handle parsing and generation of ANSI X12 documents'
12
12
  gem.homepage = 'https://github.com/tcd/x12'
13
13
  gem.licenses = 'GPL-2.0-or-later'
14
- gem.metadata['homepage_uri'] = gem.homepage
15
- gem.metadata['source_code_uri'] = 'https://github.com/tcd/x12'
14
+
15
+ gem.metadata = {
16
+ 'homepage_uri' => gem.homepage,
17
+ 'source_code_uri' => gem.homepage,
18
+ 'documentation_uri' => "https://www.rubydoc.info/gems/tcd_x12/#{gem.version}",
19
+ 'changelog_uri' => 'https://github.com/tcd/tcd_x12/blob/master/CHANGELOG.md',
20
+ 'yard.run' => 'yri' # use "yard" to build full HTML docs.
21
+ }
16
22
 
17
23
  # Specify which files should be added to the gem when it is released.
18
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -22,6 +28,7 @@ Gem::Specification.new do |gem|
22
28
  gem.require_paths = ['lib']
23
29
 
24
30
  gem.add_dependency 'libxml-ruby', '~> 3.1'
31
+
25
32
  gem.add_development_dependency 'minitest', '~> 5.0'
26
33
  gem.add_development_dependency 'rake', '~> 10.0'
27
34
  gem.add_development_dependency 'simplecov'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcd_x12
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marty Petersen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-25 00:00:00.000000000 Z
12
+ date: 2019-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libxml-ruby
@@ -78,6 +78,7 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - ".editorconfig"
80
80
  - ".gitignore"
81
+ - ".rubocop.yml"
81
82
  - CHANGELOG.md
82
83
  - Gemfile
83
84
  - LICENSE
@@ -106,6 +107,7 @@ files:
106
107
  - misc/837p.xml
107
108
  - misc/850.xml
108
109
  - misc/850dsd.xml
110
+ - misc/855.xml
109
111
  - misc/997.xml
110
112
  - misc/997single.xml
111
113
  - misc/999.xml
@@ -1927,6 +1929,9 @@ licenses:
1927
1929
  metadata:
1928
1930
  homepage_uri: https://github.com/tcd/x12
1929
1931
  source_code_uri: https://github.com/tcd/x12
1932
+ documentation_uri: https://www.rubydoc.info/gems/tcd_x12/1.6.3
1933
+ changelog_uri: https://github.com/tcd/tcd_x12/blob/master/CHANGELOG.md
1934
+ yard.run: yri
1930
1935
  post_install_message:
1931
1936
  rdoc_options: []
1932
1937
  require_paths: