eancom 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 66282d8cdd5814a9cd6ddb733530d578c025da6b215e577a0d5f890b1324295f
4
+ data.tar.gz: 39b225da80ab4dbc9886259b7cf61146e68364855f5f584c66348daee02e31d1
5
+ SHA512:
6
+ metadata.gz: a0efc78d25648823163e8e2e19b8c7e5aea2db94206bdf691ef1a2ba066501b8bc72799ad6de0d89dc42d66999600a61595dbb3f83e3a855fe088ddf7257f56c
7
+ data.tar.gz: 5791816403f0ebd74821f43c8fc8aaa8f609c9f44fb99429ed61e59eb1c91ea8122a220fc9f9ec960b2019adbad5bed239bf2301f6d536aa4f7da5f5aa6d1bfe
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in eancom.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ eancom (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ docile (1.3.2)
12
+ method_source (0.9.2)
13
+ pry (0.12.2)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ pry-nav (0.3.0)
17
+ pry (>= 0.9.10, < 0.13.0)
18
+ pry-remote (0.1.8)
19
+ pry (~> 0.9)
20
+ slop (~> 3.0)
21
+ rake (12.3.3)
22
+ rspec (3.9.0)
23
+ rspec-core (~> 3.9.0)
24
+ rspec-expectations (~> 3.9.0)
25
+ rspec-mocks (~> 3.9.0)
26
+ rspec-core (3.9.1)
27
+ rspec-support (~> 3.9.1)
28
+ rspec-expectations (3.9.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-mocks (3.9.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-support (3.9.2)
35
+ simplecov (0.18.5)
36
+ docile (~> 1.1)
37
+ simplecov-html (~> 0.11)
38
+ simplecov-html (0.12.2)
39
+ slop (3.6.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ eancom!
46
+ pry
47
+ pry-nav
48
+ pry-remote
49
+ rake (~> 12.0)
50
+ rspec (~> 3.0)
51
+ simplecov
52
+
53
+ BUNDLED WITH
54
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Fadendaten
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ # Eancom
2
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eancom"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,106 @@
1
+ Eancom::Definition.create(name: 'd96a', type: :desadv) do |document, config|
2
+ document.envelope do |envelope|
3
+ envelope.segment "UNA:+.? '"
4
+ envelope.segment "UNB" do |segment|
5
+ segment.composite "UNOC:3"
6
+ segment.composite "#{config.sender_iln}:14"
7
+ segment.composite "#{config.receiver_iln}:14"
8
+ segment.composite Time.now.strftime("%y%m%d:%H%M")
9
+ segment.composite "#{config.build_id}"
10
+ segment.composite
11
+ segment.composite "DESADV"
12
+ segment.composite
13
+ segment.composite
14
+ segment.composite "EANCOM"
15
+ end
16
+ end
17
+
18
+ document.message "UHN" do |message|
19
+
20
+ # Message ID
21
+ message.composite "1" # Message ID
22
+ message.composite "DESADV:D:96A:UN:EAN005"
23
+
24
+ message.segment "BGM" do |segment|
25
+ segment.composite "351"
26
+ segment.composite "#{config.delivery_note_id}"
27
+ segment.composite "9"
28
+ end
29
+
30
+ # Document Date
31
+ message.segment "DTM" do |segment|
32
+ segment.composite "137:#{Time.now.strftime("%Y%m%d")}:102"
33
+ end
34
+
35
+ # Shipping Date
36
+ message.segment "DTM" do |segment|
37
+ segment.composite "11:#{Time.now.strftime("%Y%m%d")}:102"
38
+ end
39
+
40
+ # Order Reference
41
+ message.segment "RFF" do |segment|
42
+ segment.composite "VN:#{config.order_id}"
43
+ end
44
+
45
+ # Sender ILN
46
+ message.segment "NAD" do |segment|
47
+ segment.composite "SU"
48
+ segment.composite "#{config.sender_iln}::9"
49
+ end
50
+
51
+ # Manufacturer ILN
52
+ message.segment "NAD" do |segment|
53
+ segment.composite "MF"
54
+ segment.composite "#{config.sender_iln}::9"
55
+ end
56
+
57
+ # Reciver ILN
58
+ message.segment "NAD" do |segment|
59
+ segment.composite "BY"
60
+ segment.composite "#{config.receiver_iln}::9"
61
+ end
62
+
63
+ # Destination ILN
64
+ message.segment "NAD" do |segment|
65
+ segment.composite "DP"
66
+ segment.composite "#{config.receiver_iln}::9"
67
+ end
68
+
69
+ # Final Recipient ILN
70
+ message.segment "NAD" do |segment|
71
+ segment.composite "UC"
72
+ segment.composite "#{config.receiver_iln}::9"
73
+ end
74
+
75
+ # Delivery Note Mode
76
+ message.segment "CPS" do |segment|
77
+ segment.composite "1"
78
+ end
79
+
80
+ # Items
81
+ total_quantity = 0
82
+ config.items.each_with_index do |item, index|
83
+ total_quantity += item.quantity.to_i
84
+
85
+ message.segment "LIN" do |segment|
86
+ segment.composite "#{index+1}"
87
+ segment.composite
88
+ segment.composite "#{item.ean}:EN"
89
+ end
90
+
91
+ message.segment "QTY" do |segment|
92
+ segment.composite "12:#{item.quantity}:PCE"
93
+ end
94
+ end
95
+
96
+ # Total Quantity
97
+ message.segment "CNT" do |segment|
98
+ segment.composite "1:#{total_quantity}"
99
+ end
100
+
101
+ # Position Count
102
+ message.segment "CNT" do |segment|
103
+ segment.composite "2:#{config.items.count}"
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/eancom/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "eancom"
5
+ spec.version = Eancom::VERSION
6
+ spec.authors = ["Fadendaten GmbH"]
7
+ spec.email = ["support@fadendaten.ch"]
8
+
9
+ spec.summary = %q{EDIFACT Generator for the EANCOM Subset}
10
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = "https://fadendaten.ch"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-remote"
28
+ spec.add_development_dependency "pry-nav"
29
+ spec.add_development_dependency "simplecov"
30
+ end
@@ -0,0 +1,43 @@
1
+ require 'eancom/version'
2
+ require 'eancom/edifact'
3
+
4
+ module Eancom
5
+
6
+ class Error < StandardError; end
7
+
8
+ FILE_TYPES = [
9
+ :desadv,
10
+ :pricat,
11
+ :ordrsp,
12
+ :salsrp,
13
+ :invrp,
14
+ :orders
15
+ ]
16
+
17
+ attr_accessor :definitions
18
+
19
+ def self.definitions
20
+ @@configs ||= Hash.new
21
+ end
22
+
23
+ def self.register_definition(definition)
24
+ type = definition.type
25
+ name = definition.name
26
+ definitions[type] ||= Hash.new
27
+ definitions[type][name] = definition
28
+ end
29
+
30
+ def self.find_definition(name:, type:)
31
+ definitions[type][name]
32
+ end
33
+ end
34
+
35
+ require "eancom/factory"
36
+ require "eancom/definition"
37
+
38
+ spec = Gem::Specification.find_by_name("eancom")
39
+ gem_root = spec.gem_dir
40
+
41
+ Dir[File.join(gem_root, "definitions", "**/*.rb")].sort.each do |file|
42
+ require file
43
+ end
@@ -0,0 +1,21 @@
1
+ module Eancom
2
+ class Definition
3
+
4
+ attr_reader :name, :type, :block
5
+
6
+ def self.create(name:, type:, &block)
7
+ definition = new(name: name, type: type, &block)
8
+ Eancom::register_definition(definition)
9
+ end
10
+
11
+ def initialize(name:, type:, &block)
12
+ @name = name
13
+ @type = type
14
+ @block = block
15
+ end
16
+
17
+ def run(document:, config:)
18
+ @block.call(document, config)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'eancom/edifact/element'
2
+ require 'eancom/edifact/document'
3
+ require 'eancom/edifact/envelope'
4
+ require 'eancom/edifact/message'
5
+ require 'eancom/edifact/segment'
6
+
7
+ module Eancom
8
+ module Edifact
9
+ DELIMITERS = {
10
+ component: ':',
11
+ data: '+',
12
+ decimal: '.',
13
+ release: '?',
14
+ reserve: ' ',
15
+ segment: "'"
16
+ }
17
+ end
18
+ end
19
+
@@ -0,0 +1,28 @@
1
+ module Eancom
2
+ module Edifact
3
+ class Document
4
+
5
+ def initialize
6
+ @envelope = Envelope.new
7
+ @message = Message.new
8
+ end
9
+
10
+ def envelope(&block)
11
+ yield(@envelope)
12
+ end
13
+
14
+ def message(name, &block)
15
+ @message.name = name
16
+ yield(@message)
17
+ end
18
+
19
+ def to_s
20
+ stream = ""
21
+ stream << @envelope.to_s
22
+ stream << @message.to_s
23
+ stream
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module Eancom
2
+ module Edifact
3
+ class Element
4
+
5
+ def segment(name = nil, &block)
6
+ segment = Segment.new(name)
7
+ yield(segment) if block
8
+ add_segment(segment)
9
+ end
10
+
11
+ def add_segment(segment)
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module Eancom
2
+ module Edifact
3
+ class Envelope < Element
4
+
5
+ def initialize
6
+ @segments = []
7
+ end
8
+
9
+ def add_segment(segment)
10
+ @segments << segment
11
+ end
12
+
13
+ def to_s
14
+ stream = ""
15
+ @segments.each do |segment|
16
+ stream << segment.to_s
17
+ stream << DELIMITERS[:segment]
18
+ end
19
+ stream
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module Eancom
2
+ module Edifact
3
+ class Message < Element
4
+
5
+ def initialize()
6
+ @me = Segment.new
7
+ @segments = [@me]
8
+ end
9
+
10
+ def add_segment(segment)
11
+ @segments << segment
12
+ end
13
+
14
+ def composite(composite)
15
+ @me.composite(composite)
16
+ end
17
+
18
+ def name=(name)
19
+ @me.name = name
20
+ end
21
+
22
+ def to_s
23
+ stream = ""
24
+ @segments.each do |segment|
25
+ stream << segment.to_s
26
+ stream << DELIMITERS[:segment]
27
+ end
28
+ stream
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ module Eancom
2
+ module Edifact
3
+ class Segment
4
+ attr_accessor :name, :composites
5
+
6
+ def initialize(name = "")
7
+ @name = name
8
+ @composites = []
9
+ end
10
+
11
+ def composite(content = "")
12
+ @composites << content
13
+ end
14
+
15
+ def to_s
16
+ stream = ""
17
+ stream << name
18
+ @composites.each do |composite|
19
+ stream << DELIMITERS[:data]
20
+ stream << composite
21
+ end
22
+ stream
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module Eancom
4
+ class Factory
5
+
6
+ attr_reader :config, :definition, :document
7
+
8
+ def initialize(json:)
9
+ @config = JSON.parse(json, object_class: OpenStruct)
10
+ @document = Eancom::Edifact::Document.new
11
+ end
12
+
13
+ def build
14
+ @definition = Eancom.find_definition(name: name, type: type)
15
+ @definition.run(document: document, config: message)
16
+ puts document.to_s
17
+ end
18
+
19
+ private
20
+
21
+ def type
22
+ type = config.type.to_sym
23
+ if Eancom::FILE_TYPES.include?(type)
24
+ type
25
+ else
26
+ raise Eancom::Error.new("EANCOM FILE TYPE NOT VALID!")
27
+ end
28
+ end
29
+
30
+ def name
31
+ config.name
32
+ end
33
+
34
+ def message
35
+ config.message
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Eancom
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eancom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fadendaten GmbH
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-remote
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-nav
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - support@fadendaten.ch
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - definitions/desadv/d96a.rb
87
+ - eancom.gemspec
88
+ - lib/eancom.rb
89
+ - lib/eancom/definition.rb
90
+ - lib/eancom/edifact.rb
91
+ - lib/eancom/edifact/document.rb
92
+ - lib/eancom/edifact/element.rb
93
+ - lib/eancom/edifact/envelope.rb
94
+ - lib/eancom/edifact/message.rb
95
+ - lib/eancom/edifact/segment.rb
96
+ - lib/eancom/factory.rb
97
+ - lib/eancom/version.rb
98
+ homepage: https://fadendaten.ch
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ homepage_uri: https://fadendaten.ch
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: EDIFACT Generator for the EANCOM Subset
122
+ test_files: []