eddy 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: f42340c2240a26ad129493767545915bfa8d6405d79691841fada80cac9ac7ee
4
- data.tar.gz: d60b37dc82e5a008e616ee98c902201df6d97808d4e215769e208a0de404bffb
3
+ metadata.gz: 54eb94b693f0ba6522fb7acdaddd77d3f84c82519f53f8cef07b1f7d67ebf556
4
+ data.tar.gz: 8baff248f6b4dfc3a52a62592540539998619d7244a6c5675ade29f60ff20eae
5
5
  SHA512:
6
- metadata.gz: 5c6ac232571b5cd098770a25c20416cfa7ce4a65be98bf5b001666185010b0d84dbf9af160406bcd1e313c35eda2a463da92b413cceee1a9458f728ab0894e3d
7
- data.tar.gz: f41c5e4c6bc496f0354e6046c1d9bec085037f529647d9ea04c4c81706c4bcd3412528413afb5166866894c19484279d098f9b35ebc6de13129a31217c7977f5
6
+ metadata.gz: 870298adcb6cab4c53100d6094edb4a1a028048fcf0cfbe49cc2977aca8412df192bca48edf15bf6a30efb0141d3cd45ea939151466e66dfed1a83647bee1b86
7
+ data.tar.gz: 60822c6c92d13a0fc96c3d33894417ed70e85cbc908302518dbe567ca6c22ee20b4b07ea3c28cea70323f4fc7565d9c089f64b7bf2baf9133ac24f747b5f7454
data/CHANGELOG.md CHANGED
@@ -13,6 +13,22 @@ All code should be considered Work In Progress.
13
13
 
14
14
  While the API is still changing, enough code exists that EDI documents can currently be written with Eddy (though I wouldn't recommend use in production environments yet).
15
15
 
16
+ ## 0.5.0 (2020-01-05)
17
+
18
+ ### Changed
19
+
20
+ - Updated the implementation of `Eddy::Interchange` and `Eddy::FunctionalGroup`
21
+ - Added arguments to the `initialize` methods of the following classes:
22
+ - `Eddy::Segments::GS`
23
+ - `Eddy::Segments::GE`
24
+ - `Eddy::Segments::ISA`
25
+ - `Eddy::Segments::IEA`
26
+ - Slightly modified file/folder layout.
27
+
28
+ ### Removed
29
+
30
+ - `Eddy::SimpleInterchange` and its associated test.
31
+
16
32
  ## 0.4.0 (2020-01-05)
17
33
 
18
34
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eddy (0.4.0)
4
+ eddy (0.5.0)
5
5
  ginny (~> 0.6.3)
6
6
  json_schemer (~> 0.2.8)
7
7
  thor (~> 1.0.1)
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [travis-ci]: https://travis-ci.org/tcd/eddy
11
11
  [coveralls]: https://coveralls.io/github/tcd/eddy?branch=master
12
12
  [license]: https://github.com/tcd/eddy/blob/master/LICENSE.txt
13
- [docs]: https://www.rubydoc.info/gems/eddy/0.4.0
13
+ [docs]: https://www.rubydoc.info/gems/eddy/0.5.0
14
14
 
15
15
  ## Installation
16
16
 
data/eddy.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  "yard.run" => "yri", # use "yard" to build full HTML docs.
23
23
  }
24
24
 
25
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
26
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
27
  end
28
28
  spec.bindir = "exe"
@@ -8,12 +8,13 @@ module Eddy
8
8
  class GE < Eddy::Segment
9
9
 
10
10
  # @param store [Eddy::Data::Store]
11
- # @param group_control_number [Integer]
11
+ # @param group_control_number [Integer] A unique *functional group control number*.
12
+ # @param number_of_transaction_sets [Integer] Number of transaction sets included in a functional group.
12
13
  # @return [void]
13
- def initialize(store, group_control_number)
14
+ def initialize(store, group_control_number, number_of_transaction_sets)
14
15
  @id = "GE"
15
16
  @name = "Functional Group Trailer"
16
- @ge01 = Eddy::Elements::E97.new(ref: "GE01", req: "M", val: store.number_of_transaction_sets_included)
17
+ @ge01 = Eddy::Elements::E97.new(ref: "GE01", req: "M", val: number_of_transaction_sets)
17
18
  @ge02 = Eddy::Elements::E28.new(ref: "GE02", req: "M", val: group_control_number)
18
19
  super(store, @ge01, @ge02)
19
20
  end
@@ -8,13 +8,13 @@ module Eddy
8
8
  class GS < Eddy::Segment
9
9
 
10
10
  # @param store [Eddy::Data::Store]
11
- # @param group_control_number [Integer]
12
- # @param transaction_set [Eddy::TransactionSet]
11
+ # @param group_control_number [Integer] A unique *functional group control number*.
12
+ # @param functional_group [String] A two-letter functional group id.
13
13
  # @return [void]
14
- def initialize(store, group_control_number, transaction_set)
14
+ def initialize(store, group_control_number, functional_group)
15
15
  @id = "GS"
16
16
  @name = "Functional Group Header"
17
- @gs01 = Eddy::Elements::E479.new(ref: "GS01", req: "M", val: transaction_set.functional_group)
17
+ @gs01 = Eddy::Elements::E479.new(ref: "GS01", req: "M", val: functional_group)
18
18
  @gs02 = Eddy::Elements::E142.new(ref: "GS02", req: "M", val: store.application_senders_code)
19
19
  @gs03 = Eddy::Elements::E124.new(ref: "GS03", req: "M", val: store.application_receivers_code)
20
20
  @gs04 = Eddy::Elements::E373.new(ref: "GS04", req: "M", val: store.time)
@@ -8,12 +8,13 @@ module Eddy
8
8
  class IEA < Eddy::Segment
9
9
 
10
10
  # @param store [Eddy::Data::Store]
11
- # @param interchange_control_number [Integer]
11
+ # @param interchange_control_number [Integer] A unique *interchange control number*.
12
+ # @param number_of_functional_groups [Integer] Number of functional groups included in an Interchange.
12
13
  # @return [void]
13
- def initialize(store, interchange_control_number)
14
+ def initialize(store, interchange_control_number, number_of_functional_groups)
14
15
  @id = "IEA"
15
16
  @name = "Interchange Control Trailer"
16
- @iea01 = Eddy::Elements::I16.new(ref: "IEA01", req: "M", val: store.number_of_included_functional_groups)
17
+ @iea01 = Eddy::Elements::I16.new(ref: "IEA01", req: "M", val: number_of_functional_groups)
17
18
  @iea02 = Eddy::Elements::I12.new(ref: "IEA02", req: "M", val: interchange_control_number)
18
19
  super(store, @iea01, @iea02)
19
20
  end
@@ -8,7 +8,7 @@ module Eddy
8
8
  class ISA < Eddy::Segment
9
9
 
10
10
  # @param store [Eddy::Data::Store]
11
- # @param interchange_control_number [Integer]
11
+ # @param interchange_control_number [Integer] A unique *interchange control number*.
12
12
  # @return [void]
13
13
  def initialize(store, interchange_control_number)
14
14
  @id = "ISA"
@@ -46,13 +46,6 @@ module Eddy
46
46
  # @return [String]
47
47
  attr_accessor :version_release_industry_id_code
48
48
 
49
- # Total number of transaction sets included in the functional group or interchange (transmission) group.
50
- # @return [Integer]
51
- attr_accessor :number_of_transaction_sets_included
52
- # A count of the number of functional groups included in an interchange.
53
- # @return [Integer]
54
- attr_accessor :number_of_included_functional_groups
55
-
56
49
  # Application Sender's Code
57
50
  # Code identifying party sending transmission; codes agreed to by trading partners
58
51
  # @return [String]
@@ -70,39 +63,34 @@ module Eddy
70
63
  self.segment_separator = "~"
71
64
  self.element_separator = "*"
72
65
  self.edi_version = "00401"
73
- self.number_of_included_functional_groups = 0
74
- self.number_of_transaction_sets_included = 0
75
66
  self.application_senders_code = "sender_id"
76
67
  self.application_receivers_code = "receiver_id"
77
68
  self.version_release_industry_id_code = "004010"
78
- @group_control_number = 1
79
69
  end
80
70
 
81
- # FIXME: not implemented
71
+ # (see Eddy::Data.new_interchange_control_number)
82
72
  #
83
73
  # @return [Integer]
84
74
  def interchange_control_number()
85
- # raise NotImplementedError
86
- return 1
75
+ return Eddy::Data.new_interchange_control_number()
87
76
  end
88
77
 
89
- # FIXME: not implemented
78
+ # (see Eddy::Data.new_transaction_set_control_number)
90
79
  #
80
+ # @param transaction_set_id [String]
91
81
  # @return [Integer]
92
- def transaction_set_control_number()
93
- # raise NotImplementedError
94
- return 1
82
+ def transaction_set_control_number(transaction_set_id)
83
+ return Eddy::Data.new_transaction_set_control_number(transaction_set_id)
95
84
  end
96
85
 
97
- # Returns an incremended value every time it's called.
86
+ # (see Eddy::Data.new_interchange_control_number)
98
87
  #
88
+ # @param functional_group [String]
99
89
  # @return [Integer]
100
- def group_control_number()
101
- old_count = @group_control_number.dup
102
- @group_control_number += 1
103
- return old_count
90
+ def functional_group_control_number(functional_group)
91
+ return Eddy::Data.new_functional_group_control_number(functional_group)
104
92
  end
105
- end
106
93
 
94
+ end
107
95
  end
108
96
  end
data/lib/eddy/data.rb CHANGED
@@ -5,6 +5,7 @@ require "eddy/data/persistence/memory"
5
5
  module Eddy
6
6
 
7
7
  # Persistent data used by Eddy.
8
+ #
8
9
  # @return [Eddy::Data::Persistence::Base]
9
10
  def self.data
10
11
  return @data if defined?(@data) && !@data.nil?
@@ -32,6 +33,8 @@ module Eddy
32
33
  # Code for storing & generating data used by Eddy when generating EDI documents.
33
34
  module Data
34
35
 
36
+ # Return a new, unique number.
37
+ #
35
38
  # @return [Integer]
36
39
  def self.new_interchange_control_number
37
40
  existing = Eddy.data.interchange_control_numbers()
@@ -40,24 +43,27 @@ module Eddy
40
43
  return new_ctrl_num
41
44
  end
42
45
 
43
- # @param functional_group [String]
46
+ # Return a new, unique number.
47
+ #
48
+ # @param transaction_set_id [String]
44
49
  # @return [Integer]
45
- def self.new_functional_group_control_number(functional_group)
46
- existing = Eddy.data.functional_group_control_numbers(functional_group)
50
+ def self.new_transaction_set_control_number(transaction_set_id)
51
+ existing = Eddy.data.transaction_set_control_numbers(transaction_set_id)
47
52
  new_ctrl_num = Eddy::Util.new_number(existing)
48
- Eddy.data.add_functional_group_control_number(functional_group, new_ctrl_num)
53
+ Eddy.data.add_transaction_set_control_number(transaction_set_id, new_ctrl_num)
49
54
  return new_ctrl_num
50
55
  end
51
56
 
52
- # @param transaction_set_id [String]
57
+ # Return a new, unique number.
58
+ #
59
+ # @param functional_group [String]
53
60
  # @return [Integer]
54
- def self.new_transaction_set_control_number(transaction_set_id)
55
- existing = Eddy.data.transaction_set_control_numbers(transaction_set_id)
61
+ def self.new_functional_group_control_number(functional_group)
62
+ existing = Eddy.data.functional_group_control_numbers(functional_group)
56
63
  new_ctrl_num = Eddy::Util.new_number(existing)
57
- Eddy.data.transaction_set_control_numbers(transaction_set_id, new_ctrl_num)
64
+ Eddy.data.add_functional_group_control_number(functional_group, new_ctrl_num)
58
65
  return new_ctrl_num
59
66
  end
60
67
 
61
68
  end
62
-
63
69
  end
@@ -2,31 +2,33 @@ module Eddy
2
2
  # A group of `Eddy::TransactionSet::Base` classes.
3
3
  class FunctionalGroup
4
4
 
5
+ # @return [String]
6
+ attr_reader :id
5
7
  # @return [Eddy::Data::Store] Data store for the Interchange and all encompassed components.
6
8
  attr_accessor :store
7
- # Class for making new Transaction Sets.
8
- # @return [Eddy::TransactionSet]
9
- attr_accessor :transaction_set
10
- # An array of Transaction Set instances
9
+ # An array of Transaction Set instances.
11
10
  # @return [Array<Eddy::TransactionSet>]
12
11
  attr_accessor :transaction_sets
13
12
 
14
13
  # @param store [Eddy::Data::Store]
15
- # @param transaction_set [Eddy::TransactionSet]
14
+ # @param transaction_sets [Eddy::TransactionSet]
16
15
  # @return [void]
17
- def initialize(store, transaction_set)
16
+ def initialize(store, *transaction_sets)
18
17
  self.store = store
19
- self.transaction_set = transaction_set
20
- self.transaction_sets = []
18
+ transaction_sets.flatten!
19
+ self.transaction_sets = transaction_sets || []
20
+ if self.transaction_sets.length == 0
21
+ raise ArgumentError, "At least one transaction set is required to create a functional group"
22
+ end
23
+ @id = self.transaction_sets.first.functional_group
21
24
  end
22
25
 
23
- # @return [String]
26
+ # @return [Array<#render>]
24
27
  def render()
25
- number_of_included_functional_groups = self.store.number_of_included_functional_groups
26
- gs = Eddy::Segments::GS.new(store, number_of_included_functional_groups, self.transaction_set)
27
- ge = Eddy::Segments::GE.new(store, number_of_included_functional_groups, self.transaction_set)
28
- segments = [gs, self.transaction_sets, ge].flatten
29
- return segments.join(self.store.segment_separator) + segment_separator
28
+ f_group_ctrl_num = Eddy::Data.new_functional_group_control_number(@id)
29
+ gs = Eddy::Segments::GS.new(store, f_group_ctrl_num, @id)
30
+ ge = Eddy::Segments::GE.new(store, f_group_ctrl_num, self.transaction_sets.length)
31
+ return [gs, self.transaction_sets, ge].flatten.map(&:render)
30
32
  end
31
33
 
32
34
  end
@@ -3,13 +3,14 @@ module Eddy
3
3
  class Interchange
4
4
  # @return [Eddy::Data::Store] Data store for the Interchange.
5
5
  attr_accessor :store
6
- # @return [Array<Eddy::Write::FunctionalGroup>]
7
- attr_accessor :functional_groups
6
+ # @return [Array<Eddy::TransactionSet>]
7
+ attr_accessor :transaction_sets
8
8
 
9
+ # @param store [Eddy::Data::Store] (Eddy::Data::Store.new)
9
10
  # @return [void]
10
- def initialize()
11
- self.store = Eddy::Data::Store.new()
12
- self.functional_groups = []
11
+ def initialize(store = Eddy::Data::Store.new())
12
+ self.store = store
13
+ self.transaction_sets = []
13
14
  end
14
15
 
15
16
  # @param _transaction_sets [Array<Eddy::TransactionSet>]
@@ -21,7 +22,36 @@ module Eddy
21
22
 
22
23
  # @return [String]
23
24
  def render()
24
- raise NotImplementedError
25
+ ctrl_num = Eddy::Data.new_interchange_control_number()
26
+ f_groups = self.functional_groups()
27
+ sep = self.store.segment_separator
28
+ isa = Eddy::Segments::ISA.new(self.store, ctrl_num)
29
+ iea = Eddy::Segments::IEA.new(self.store, ctrl_num, f_groups.length)
30
+ yield(isa, iea) if block_given?
31
+ return [isa, f_groups, iea].flatten.map(&:render).join(sep) + sep
32
+ end
33
+
34
+ # @return [Array<Eddy::FunctionalGroup>]
35
+ def functional_groups()
36
+ sorted_sets = {}
37
+ self.transaction_sets.each do |ts|
38
+ sorted_sets[ts.functional_group] ||= []
39
+ sorted_sets[ts.functional_group] << ts
40
+ end
41
+ return sorted_sets.map { |_, value| Eddy::FunctionalGroup.new(self.store, *value) }
42
+ end
43
+
44
+ private
45
+
46
+ # @raise [ArgumentError] Unless `transaction_set` is a subclass of {Eddy::TransactionSet}
47
+ # @param transaction_set [Eddy::TransactionSet]
48
+ # @return [void]
49
+ def verify_transaction_set(transaction_set)
50
+ raise ArgumentError unless transaction_set < Eddy::TransactionSet
51
+ raise ArgumentError unless transaction_set <= Eddy::TransactionSet
52
+ raise ArgumentError unless transaction_set.ancestors.include?(Eddy::TransactionSet)
53
+ raise ArgumentError unless transaction_set.superclass == Eddy::TransactionSet
54
+ return nil
25
55
  end
26
56
 
27
57
  end
@@ -55,16 +55,16 @@ module Eddy
55
55
 
56
56
  # Add `ST` and `SE` segments to the `components` array.
57
57
  #
58
- # @param t_set_control_number [Integer] (Eddy::Data::Store#transaction_set_control_number)
58
+ # @param control_number [Integer] (Eddy::Data.new_transaction_set_control_number())
59
59
  # @return [void]
60
- def add_envelope(t_set_control_number = self.store.transaction_set_control_number)
60
+ def add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id))
61
61
  st = Eddy::Segments::ST.new(self.store)
62
62
  st.TransactionSetIdentifierCode = self.id
63
- st.TransactionSetControlNumber = t_set_control_number
63
+ st.TransactionSetControlNumber = control_number
64
64
 
65
65
  se = Eddy::Segments::SE.new(self.store)
66
66
  se.NumberOfIncludedSegments = self.all_components.length + 2
67
- se.TransactionSetControlNumber = t_set_control_number
67
+ se.TransactionSetControlNumber = control_number
68
68
 
69
69
  self.components.unshift(st)
70
70
  self.components.push(se)
@@ -77,8 +77,7 @@ module Eddy
77
77
  # @return [String]
78
78
  def render(s_sep = self.store.segment_separator)
79
79
  add_envelope()
80
- e_sep = self.store.element_separator
81
- return self.all_components.map { |s| s.render(e_sep) }.join(s_sep) + s_sep
80
+ return self.all_components.map { |s| s.render(self.store.element_separator) }.join(s_sep)
82
81
  end
83
82
 
84
83
  # Return all contained Segments in a single, flattened array.
data/lib/eddy/models.rb CHANGED
@@ -5,7 +5,6 @@ require "eddy/models/loop/base"
5
5
  require "eddy/models/transaction_set"
6
6
  require "eddy/models/functional_group"
7
7
  require "eddy/models/interchange"
8
- require "eddy/models/simple_interchange"
9
8
 
10
9
  module Eddy
11
10
  # Classes modeling EDI components.
data/lib/eddy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eddy
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay Dunston
@@ -1523,7 +1523,6 @@ files:
1523
1523
  - lib/eddy/models/loop/base.rb
1524
1524
  - lib/eddy/models/loop/repeat.rb
1525
1525
  - lib/eddy/models/segment.rb
1526
- - lib/eddy/models/simple_interchange.rb
1527
1526
  - lib/eddy/models/transaction_set.rb
1528
1527
  - lib/eddy/parse.rb
1529
1528
  - lib/eddy/schema/element_summary.rb
@@ -1554,7 +1553,7 @@ metadata:
1554
1553
  homepage_uri: https://github.com/tcd/eddy
1555
1554
  source_code_uri: https://github.com/tcd/eddy
1556
1555
  changelog_uri: https://github.com/tcd/eddy/blob/master/CHANGELOG.md
1557
- documentation_uri: https://www.rubydoc.info/gems/eddy/0.4.0
1556
+ documentation_uri: https://www.rubydoc.info/gems/eddy/0.5.0
1558
1557
  yard.run: yri
1559
1558
  post_install_message:
1560
1559
  rdoc_options: []
@@ -1,57 +0,0 @@
1
- module Eddy
2
- # An EDI interchange with one Transaction Set.
3
- class SimpleInterchange
4
- # @return [Eddy::Data::Store] Data store for the Interchange and all encompassed components.
5
- attr_accessor :store
6
- # @return [Eddy::TransactionSet]
7
- attr_accessor :transaction_set
8
- # @return [Array]
9
- attr_accessor :components
10
-
11
- # Initialize an interchange with one Functional Group containing one Transaction Set.
12
- #
13
- # @param transaction_set [Eddy::TransactionSet]
14
- # @param store [Eddy::Data::Store] (Eddy::Data::Store.new)
15
- # @return [void]
16
- def initialize(transaction_set, store: Eddy::Data::Store.new())
17
- self.components = []
18
- self.transaction_set = transaction_set
19
- self.store = store
20
- self.store.number_of_transaction_sets_included = 1
21
- self.store.number_of_included_functional_groups = 1
22
- end
23
-
24
- # @yieldparam [Eddy::Segments::ISA] isa
25
- # @yieldparam [Eddy::Segments::IEA] iea
26
- # @yieldparam [Eddy::Segments::GS] gs
27
- # @yieldparam [Eddy::Segments::GE] ge
28
- # @return [String]
29
- def render()
30
- itch_ctrl_num = Eddy::Data.new_interchange_control_number()
31
- isa = Eddy::Segments::ISA.new(store, itch_ctrl_num)
32
- iea = Eddy::Segments::IEA.new(store, itch_ctrl_num)
33
- number_of_included_functional_groups = self.store.number_of_included_functional_groups
34
- gs = Eddy::Segments::GS.new(store, number_of_included_functional_groups, self.transaction_set)
35
- ge = Eddy::Segments::GE.new(store, number_of_included_functional_groups)
36
- yield(isa, iea, gs, ge) if block_given?
37
- self.components.prepend(gs)
38
- self.components.prepend(isa)
39
- self.components.append(ge)
40
- self.components.append(iea)
41
- segments = self.components.map(&:render).flatten().join(store.segment_separator) + store.segment_separator
42
- return segments
43
- end
44
-
45
- # @raise [ArgumentError] Unless `transaction_set` is a subclass of {Eddy::TransactionSet}
46
- # @param transaction_set [Eddy::TransactionSet]
47
- # @return [void]
48
- def verify_transaction_set(transaction_set)
49
- raise ArgumentError unless transaction_set < Eddy::TransactionSet
50
- raise ArgumentError unless transaction_set <= Eddy::TransactionSet
51
- raise ArgumentError unless transaction_set.ancestors.include?(Eddy::TransactionSet)
52
- raise ArgumentError unless transaction_set.superclass == Eddy::TransactionSet
53
- return nil
54
- end
55
-
56
- end
57
- end