baldr 0.0.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.
- data/lib/baldr/builder.rb +25 -0
- data/lib/baldr/grammar/set997.rb +19 -0
- data/lib/baldr/loop.rb +28 -0
- data/lib/baldr/segment.rb +28 -0
- data/lib/baldr/version.rb +3 -0
- data/lib/baldr.rb +1 -0
- metadata +50 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
class Baldr::Builder
|
2
|
+
|
3
|
+
DEFAULT_SEPARATORS = {
|
4
|
+
element: '*',
|
5
|
+
segment: '~'
|
6
|
+
}.freeze
|
7
|
+
|
8
|
+
attr_accessor :separators
|
9
|
+
|
10
|
+
def initialize(params = {})
|
11
|
+
@children = []
|
12
|
+
@separators = params[:separators] || DEFAULT_SEPARATORS
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
child = VanillaX12::Segment.new(method, self)
|
17
|
+
child.instance_eval &block
|
18
|
+
@children << child
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
@children.map(&:draw).join("\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Baldr::Grammar::Set997
|
2
|
+
|
3
|
+
FUNCTIONAL_GROUP = 'FA'
|
4
|
+
|
5
|
+
STRUCTURE = [
|
6
|
+
{id: 'ST', min: 1, max: 1, level: [
|
7
|
+
{id: 'AK1', min: 1, max: 1},
|
8
|
+
{id: 'AK2', min: 0, max: 999999, level: [
|
9
|
+
{id: 'AK3', min: 0, max: 999999, level: [
|
10
|
+
{id: 'AK4', min: 0, max: 99},
|
11
|
+
]},
|
12
|
+
{id: 'AK5', min: 1, max: 1},
|
13
|
+
]},
|
14
|
+
{id: 'AK9', min: 1, max: 1},
|
15
|
+
{id: 'SE', min: 1, max: 1},
|
16
|
+
]}
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
end
|
data/lib/baldr/loop.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Baldr::Loop
|
2
|
+
|
3
|
+
def initialize(id, builder)
|
4
|
+
@elements = []
|
5
|
+
@children = []
|
6
|
+
@builder = builder
|
7
|
+
@id = id.upcase.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
if method.to_s.start_with?(@id)
|
12
|
+
element = method.to_s[-2..-1].to_i - 1
|
13
|
+
@elements[element] = args[0]
|
14
|
+
else
|
15
|
+
child = VanillaX12::Segment.new(method, @builder)
|
16
|
+
child.instance_eval &block if block_given?
|
17
|
+
@children << child
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
a = [@id] + @elements
|
23
|
+
s = @builder.separators
|
24
|
+
result = ["#{a.join(s[:element])}#{s[:segment]}"] + @children.map{ |c| c.draw }
|
25
|
+
result.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Baldr::Segment
|
2
|
+
|
3
|
+
def initialize(id, builder)
|
4
|
+
@elements = []
|
5
|
+
@children = []
|
6
|
+
@builder = builder
|
7
|
+
@id = id.upcase.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
if method.to_s.start_with?(@id)
|
12
|
+
element = method.to_s[-2..-1].to_i - 1
|
13
|
+
@elements[element] = args[0]
|
14
|
+
else
|
15
|
+
child = VanillaX12::Loop.new(method, @builder)
|
16
|
+
child.instance_eval &block if block_given?
|
17
|
+
@children << child
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
a = [@id] + @elements
|
23
|
+
s = @builder.separators
|
24
|
+
result = ["#{a.join(s[:element])}#{s[:segment]}"] + @children.map{ |c| c.draw }
|
25
|
+
result.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/baldr.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'baldr/version'
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baldr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Stanislav Spiridonov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Lightweight EDI X12 translator
|
15
|
+
email: stanislav@spiridonov.pro
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/baldr.rb
|
21
|
+
- lib/baldr/builder.rb
|
22
|
+
- lib/baldr/grammar/set997.rb
|
23
|
+
- lib/baldr/loop.rb
|
24
|
+
- lib/baldr/segment.rb
|
25
|
+
- lib/baldr/version.rb
|
26
|
+
homepage: https://github.com/spiridonov/baldr
|
27
|
+
licenses: []
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.23
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Baldr, Odin`s son
|
50
|
+
test_files: []
|