edifact_rails 1.1.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 +7 -0
- data/.github/CODE_OF_CONDUCT.md +46 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +169 -0
- data/lib/edifact_rails/parser.rb +125 -0
- data/lib/edifact_rails/version.rb +5 -0
- data/lib/edifact_rails.rb +14 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1343d4c915c6df4b716c31560cf58d5b350dc18ad074c12c3c562b13b0ce3717
|
4
|
+
data.tar.gz: 6067a62e4bdf24f2be92306a6aa4d4e21b9aa3b69ac6eff3eba8a8ae97229627
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e1ce36c70da1e16fce1596fd43b345f5a284a77b82645b901d6eb88f25ae45c45d152aae760477526bd1c0230f59890f602c40fbded3cd3be61a80a8926e1c7
|
7
|
+
data.tar.gz: 2feffb89e9df203d37eb0f8aab6bcb673630dd637092a5fe406de9eff0d244d074fd964b1d10e7c68a75a48b9f75f58168240d42e7c2d900f469468be0a049d5
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@lokalise.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
1. [Fork the repository.][fork]
|
4
|
+
2. [Create a topic branch.][branch]
|
5
|
+
3. Implement your feature or bug fix.
|
6
|
+
4. Don't forget to add specs and make sure they pass by running `rspec .`.
|
7
|
+
5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you.
|
8
|
+
6. If necessary, add documentation for your feature or bug fix.
|
9
|
+
7. Commit and push your changes.
|
10
|
+
8. [Submit a pull request.][pr]
|
11
|
+
|
12
|
+
[fork]: http://help.github.com/fork-a-repo/
|
13
|
+
[branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
|
14
|
+
[pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
|
@@ -0,0 +1,11 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request. Were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here.
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 David Blackwood
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
# EdifactRails
|
2
|
+
|
3
|
+
This gem parses EDIFACT or TRADACOMS input, and converts it into a ruby array structure for whatever further processing or validation you desire.
|
4
|
+
|
5
|
+
It does not handle validation itself.
|
6
|
+
|
7
|
+
This gem is heavily inspired by and attempts to output similar results as [edifact_parser](https://github.com/pvdvreede/edifact_parser), credits to [pvdvreede](https://github.com/pvdvreede)
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
This gem requires Ruby 3.0+.
|
12
|
+
|
13
|
+
This gem has been tested on the following ruby versions:
|
14
|
+
* 3.0.6
|
15
|
+
* 3.1.2
|
16
|
+
* 3.2.2
|
17
|
+
|
18
|
+
## Getting started
|
19
|
+
|
20
|
+
In your `Gemfile`:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'edifact_rails', '~> 1.0'
|
24
|
+
```
|
25
|
+
|
26
|
+
Otherwise:
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install edifact_rails
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
If you don't have the gem in your `Gemfile`, you will need to:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'edifact_rails'
|
38
|
+
```
|
39
|
+
|
40
|
+
You can pass either the path to your EDIFACT (or TRADACOMS) file, or a document (or snippet) as a string:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
ruby_array = EdifactRails.parse_file("your/file/path")
|
44
|
+
```
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
ruby_array = EdifactRails.parse("LIN+1+1+0764569104:IB'QTY+1:25'")
|
48
|
+
```
|
49
|
+
|
50
|
+
## Output
|
51
|
+
|
52
|
+
### EDIFACT
|
53
|
+
|
54
|
+
This example EDIFACT file:
|
55
|
+
|
56
|
+
```
|
57
|
+
UNA:+.? '
|
58
|
+
UNB+UNOA:3+TESTPLACE:1+DEP1:1+20051107:1159+6002'
|
59
|
+
UNH+SSDD1+ORDERS:D:03B:UN:EAN008'
|
60
|
+
BGM+220+BKOD99+9'
|
61
|
+
DTM+137:20051107:102'
|
62
|
+
NAD+BY+5412345000176::9'
|
63
|
+
NAD+SU+4012345000094::9'
|
64
|
+
LIN+1+1+0764569104:IB'
|
65
|
+
QTY+1:25'
|
66
|
+
FTX+AFM+1++XPath 2.0 Programmer?'s Reference'
|
67
|
+
LIN+2+1+0764569090:IB'
|
68
|
+
QTY+1:25'
|
69
|
+
FTX+AFM+1++XSLT 2.0 Programmer?'s Reference'
|
70
|
+
LIN+3+1+1861004656:IB'
|
71
|
+
QTY+1:16'
|
72
|
+
FTX+AFM+1++Java Server Programming'
|
73
|
+
LIN+4+1+0596006756:IB'
|
74
|
+
QTY+1:10'
|
75
|
+
FTX+AFM+1++Enterprise Service Bus'
|
76
|
+
UNS+S'
|
77
|
+
CNT+2:4'
|
78
|
+
UNT+22+SSDD1'
|
79
|
+
UNZ+1+6002'
|
80
|
+
```
|
81
|
+
|
82
|
+
Will be returned as:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
[
|
86
|
+
["UNB", ["UNOA", 3], ["TESTPLACE", 1], ["DEP1", 1], [20051107, 1159], [6002]],
|
87
|
+
["UNH", ["SSDD1"], ["ORDERS", "D", "03B", "UN", "EAN008"]],
|
88
|
+
["BGM", [220], ["BKOD99"], [9]],
|
89
|
+
["DTM", [137, 20051107, 102]],
|
90
|
+
["NAD", ["BY"], [5412345000176, nil, 9]],
|
91
|
+
["NAD", ["SU"], [4012345000094, nil, 9]],
|
92
|
+
["LIN", [1], [1], ["0764569104", "IB"]],
|
93
|
+
["QTY", [1, 25]],
|
94
|
+
["FTX", ["AFM"], [1], [], ["XPath 2.0 Programmer's Reference"]],
|
95
|
+
["LIN", [2], [1], ["0764569090", "IB"]],
|
96
|
+
["QTY", [1, 25]],
|
97
|
+
["FTX", ["AFM"], [1], [], ["XSLT 2.0 Programmer's Reference"]],
|
98
|
+
["LIN", [3], [1], [1861004656, "IB"]],
|
99
|
+
["QTY", [1, 16]],
|
100
|
+
["FTX", ["AFM"], [1], [], ["Java Server Programming"]],
|
101
|
+
["LIN", [4], [1], ["0596006756", "IB"]],
|
102
|
+
["QTY", [1, 10]],
|
103
|
+
["FTX", ["AFM"], [1], [], ["Enterprise Service Bus"]],
|
104
|
+
["UNS", ["S"]],
|
105
|
+
["CNT", [2, 4]],
|
106
|
+
["UNT", [22], ["SSDD1"]],
|
107
|
+
["UNZ", [1], [6002]]
|
108
|
+
]
|
109
|
+
```
|
110
|
+
|
111
|
+
### TRADACOMS
|
112
|
+
|
113
|
+
This TRADACOMS file:
|
114
|
+
|
115
|
+
```
|
116
|
+
STX=ANA:1+5000169000001:DAVEY PLC+5060073022052:Blackwood Limited+230102:050903+3800++ORDHDR'
|
117
|
+
MHD=1+ORDHDR:9'
|
118
|
+
TYP=0430+NEW-ORDERS'
|
119
|
+
SDT=5060073022052:005096+BLACKWOOD LTD'
|
120
|
+
CDT=5000169000001:WINDRAKER LTD'
|
121
|
+
FIL=3800+1+230102'
|
122
|
+
MTR=14'
|
123
|
+
MHD=4+ORDERS:9'
|
124
|
+
CLO=:777:BLACKWOOD D'
|
125
|
+
ORD=B1102300::230102++N'
|
126
|
+
DIN=230103+++PM'
|
127
|
+
OLD=1+:5000169475119+5000169847442+:047836+12+68++++WR TStem Broccoli Spears'
|
128
|
+
DNB=1+1++::128:KENYA/JOR/UK:142::202:060123'
|
129
|
+
OLD=2+:5000169073643+5000169159491+:085482+16+15++++WR Asparagus:IFCO 410'
|
130
|
+
DNB=2+1++108:200:128:?+?+?+:142::202:080123'
|
131
|
+
OLD=3+:5000169073629+5000169048726+:085486+12+28++++WR Fine Asparagus'
|
132
|
+
DNB=3+1++108:225:128:THAI/peru:142::202:070123'
|
133
|
+
OTR=3'
|
134
|
+
MTR=12'
|
135
|
+
MHD=5+ORDTLR:9'
|
136
|
+
OFT=3'
|
137
|
+
MTR=3'
|
138
|
+
END=5
|
139
|
+
```
|
140
|
+
|
141
|
+
Will be returned as:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
[
|
145
|
+
['STX', ['ANA', 1], [5000169000001, 'DAVEY PLC'], [5060073022052, 'Blackwood Limited'], [230102, '050903'], [3800], [], ['ORDHDR']],
|
146
|
+
['MHD', [1], ['ORDHDR', 9]],
|
147
|
+
['TYP', ['0430'], ['NEW-ORDERS']],
|
148
|
+
['SDT', [5060073022052, '005096'], ['BLACKWOOD LTD']],
|
149
|
+
['CDT', [5000169000001, 'WINDRAKER LTD']],
|
150
|
+
['FIL', [3800], [1], [230102]],
|
151
|
+
['MTR', [14]],
|
152
|
+
['MHD', [4], ['ORDERS', 9]],
|
153
|
+
['CLO', [nil, 777, 'BLACKWOOD D']],
|
154
|
+
['ORD', ['B1102300', nil, 230102], [], ['N']],
|
155
|
+
['DIN', [230103], [], [], ['PM']],
|
156
|
+
['OLD', [1], [nil, 5000169475119], [5000169847442], [nil, '047836'], [12], [68], [], [], [], ['WR TStem Broccoli Spears']],
|
157
|
+
['DNB', [1], [1], [], [nil, nil, 128, 'KENYA/JOR/UK', 142, nil, 202, '060123']],
|
158
|
+
['OLD', [2], [nil, 5000169073643], [5000169159491], [nil, '085482'], [16], [15], [], [], [], ['WR Asparagus', 'IFCO 410']],
|
159
|
+
['DNB', [2], [1], [], [108, 200, 128, '+++', 142, nil, 202, '080123']],
|
160
|
+
['OLD', [3], [nil, 5000169073629], [5000169048726], [nil, '085486'], [12], [28], [], [], [], ['WR Fine Asparagus']],
|
161
|
+
['DNB', [3], [1], [], [108, 225, 128, 'THAI/peru', 142, nil, 202, '070123']],
|
162
|
+
['OTR', [3]],
|
163
|
+
['MTR', [12]],
|
164
|
+
['MHD', [5], ['ORDTLR', 9]],
|
165
|
+
['OFT', [3]],
|
166
|
+
['MTR', [3]],
|
167
|
+
['END', [5]]
|
168
|
+
]
|
169
|
+
```
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EdifactRails
|
4
|
+
class Parser
|
5
|
+
ESCAPE_CHARACTER = "?"
|
6
|
+
SEGMENT_SEPARATOR = "'"
|
7
|
+
DATA_ELEMENT_SEPARATOR = "+"
|
8
|
+
COMPONENT_DATA_ELEMENT_SEPARATOR = ":"
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
# Escape the special characters for use in regex later on
|
12
|
+
@escape_char_rx = Regexp.quote(EdifactRails::Parser::ESCAPE_CHARACTER)
|
13
|
+
@segment_separator_rx = Regexp.quote(EdifactRails::Parser::SEGMENT_SEPARATOR)
|
14
|
+
@data_element_separator_rx = Regexp.quote(EdifactRails::Parser::DATA_ELEMENT_SEPARATOR)
|
15
|
+
@component_data_element_separator_rx = Regexp.quote(EdifactRails::Parser::COMPONENT_DATA_ELEMENT_SEPARATOR)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Treat the input a little, split the input string into segments, parse them
|
19
|
+
def parse(string)
|
20
|
+
string = treat_input(string)
|
21
|
+
|
22
|
+
# Split the input string into segments
|
23
|
+
segments = string.split(/(?<!#{@escape_char_rx})#{@segment_separator_rx}/)
|
24
|
+
|
25
|
+
# Detect if the input is a tradacoms file
|
26
|
+
@is_tradacoms = segments.map { |s| s[3] }.uniq == ["="]
|
27
|
+
|
28
|
+
# Drop the UNA segment, if present
|
29
|
+
segments.reject! { |s| s[0..2] == "UNA" }
|
30
|
+
|
31
|
+
# Parse the segments
|
32
|
+
segments.map { |segment| parse_segment(segment) }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def treat_input(string)
|
38
|
+
# Trim newlines and excess spaces around those newlines
|
39
|
+
string = string.gsub(/\s*\n\s*/, "")
|
40
|
+
|
41
|
+
# Prepare regex
|
42
|
+
other_specials_rx = Regexp.quote(
|
43
|
+
[
|
44
|
+
EdifactRails::Parser::SEGMENT_SEPARATOR,
|
45
|
+
EdifactRails::Parser::DATA_ELEMENT_SEPARATOR,
|
46
|
+
EdifactRails::Parser::COMPONENT_DATA_ELEMENT_SEPARATOR
|
47
|
+
].join
|
48
|
+
)
|
49
|
+
|
50
|
+
# If there is an EVEN number of escape characters before a special character,
|
51
|
+
# the special character is therefore unescaped.
|
52
|
+
# Add a space between these even number of escapes, and the special character
|
53
|
+
#
|
54
|
+
# This means the regex logic for #splitting on special characters is now consistent, since there will only ever
|
55
|
+
# be either 0 or 1 escape characters before every special character.
|
56
|
+
#
|
57
|
+
# We have to do this because we can't negative lookbehind for 'an even number of escape characters' since
|
58
|
+
# lookbehinds have to be fixed length.
|
59
|
+
#
|
60
|
+
# The added space, which is now at the boundry of a component,
|
61
|
+
# will get cut by the #strip! in #treat_component eventually
|
62
|
+
#
|
63
|
+
# I must admit this kind of thing is why you should use an actual parser instead of regex for, you know, parsing
|
64
|
+
#
|
65
|
+
# "LIN+even????+123" => '+' is not escaped, gsub'ed => "even???? +123" => parsed => ['LIN', ['even??'], [123]]
|
66
|
+
# "LIN+odd???+123" => '+' is escaped, not gsub'ed => "odd???+123" => parsed => ['LIN', ['odd?+123']]
|
67
|
+
string.gsub(/(?<!#{@escape_char_rx})((#{@escape_char_rx}{2})+)([#{other_specials_rx}])/, '\1 \3')
|
68
|
+
end
|
69
|
+
|
70
|
+
# Split the segment into data elements, take the first as the tag, then parse the rest
|
71
|
+
def parse_segment(segment)
|
72
|
+
# If the input is a tradacoms file, the segment tag will be proceeded by '=' instead of '+'
|
73
|
+
# 'QTY=1+A:B' instead of 'QTY+1+A:B'
|
74
|
+
# Fortunately, this is easily handled by simply changing these "="s into "+"s before the split
|
75
|
+
segment[3] = EdifactRails::Parser::DATA_ELEMENT_SEPARATOR if @is_tradacoms && segment.length >= 4
|
76
|
+
|
77
|
+
# Segments are made up of data elements
|
78
|
+
data_elements = segment.split(/(?<!#{@escape_char_rx})#{@data_element_separator_rx}/)
|
79
|
+
|
80
|
+
# The first element is the tag, pop it off
|
81
|
+
parsed_segment = []
|
82
|
+
parsed_segment.push(data_elements.shift) if data_elements.any?
|
83
|
+
|
84
|
+
# Parse the data elements
|
85
|
+
parsed_segment.concat(data_elements.map { |element| parse_data_element(element) })
|
86
|
+
end
|
87
|
+
|
88
|
+
# Split the data elements into component data elements, and treat them
|
89
|
+
def parse_data_element(element)
|
90
|
+
# Split data element into components
|
91
|
+
components = element.split(/(?<!#{@escape_char_rx})#{@component_data_element_separator_rx}/)
|
92
|
+
|
93
|
+
components.map { |component| treat_component(component) }
|
94
|
+
end
|
95
|
+
|
96
|
+
# Strip, remove escape characters, convert to nil where needed, convert to integer where needed
|
97
|
+
def treat_component(component)
|
98
|
+
# Remove surrounding whitespace
|
99
|
+
component.strip!
|
100
|
+
|
101
|
+
# Prepare regex
|
102
|
+
all_special_characters = [
|
103
|
+
EdifactRails::Parser::SEGMENT_SEPARATOR,
|
104
|
+
EdifactRails::Parser::DATA_ELEMENT_SEPARATOR,
|
105
|
+
EdifactRails::Parser::COMPONENT_DATA_ELEMENT_SEPARATOR,
|
106
|
+
EdifactRails::Parser::ESCAPE_CHARACTER
|
107
|
+
].join
|
108
|
+
|
109
|
+
# If the component has escaped characters in it, remove the escape character and return the character as is
|
110
|
+
# "?+" -> "+", "??" -> "?"
|
111
|
+
component.gsub!(/#{@escape_char_rx}([#{Regexp.quote(all_special_characters)}])/, '\1')
|
112
|
+
|
113
|
+
# Convert empty strings to nils
|
114
|
+
component = nil if component.empty?
|
115
|
+
|
116
|
+
# Convert the component to integer if it is one
|
117
|
+
# "1" -> 1
|
118
|
+
# "-123" -> -123
|
119
|
+
# "0350" -> "0350"
|
120
|
+
component = component.to_i if component.to_i.to_s == component
|
121
|
+
|
122
|
+
component
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "edifact_rails/parser"
|
4
|
+
|
5
|
+
module EdifactRails
|
6
|
+
def self.parse(string)
|
7
|
+
parser = EdifactRails::Parser.new
|
8
|
+
parser.parse string
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse_file(file_path)
|
12
|
+
parse(File.read(file_path).split("\n").join)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edifact_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Blackwood
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.50'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.50'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-performance
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.20'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.20'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
111
|
+
description: This gem allows you to pass in a EDIFACT string or file, and returns
|
112
|
+
an array structure, to enable additional processing and validation
|
113
|
+
email: david.blackwood.94@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- README.md
|
118
|
+
files:
|
119
|
+
- ".github/CODE_OF_CONDUCT.md"
|
120
|
+
- ".github/CONTRIBUTING.md"
|
121
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- lib/edifact_rails.rb
|
127
|
+
- lib/edifact_rails/parser.rb
|
128
|
+
- lib/edifact_rails/version.rb
|
129
|
+
homepage: https://github.com/david-blackwood/edifact_rails
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata:
|
133
|
+
rubygems_mfa_required: 'true'
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 3.0.0
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubygems_version: 3.2.33
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Ruby gem that parses an EDIFACT input into a ruby array structure
|
153
|
+
test_files: []
|