edifact_rails 1.2.0 → 1.2.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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +3 -2
- data/lib/edifact_rails/parser.rb +13 -12
- data/lib/edifact_rails/version.rb +1 -1
- data/lib/edifact_rails.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c51652b41747f2b0c07ecd834c5c79b3bebbb1537464a450f37ee58ea68150e
|
4
|
+
data.tar.gz: 2669313b30c7565c60f4dc568c528127577770946f7d4a8ffee7a1fc87f4c07e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ded47109a99423254023e4f7316e1bdc3d1dc6602e73225a900c815baa2b2c4d9d14fe16f131aa5e1239b6b49ecab6394d7051ec9fc66923c6ffb5eb0e674ba5
|
7
|
+
data.tar.gz: f3c9d7ae8f793651c62eff11b3356321f6bcc531b5ce61020f23d530a08b0112d46e338edc8ff1711bc514fb53875508b5792795c3cbea8056e5ee97a60e52f1
|
data/CHANGELOG.md
CHANGED
@@ -15,4 +15,9 @@
|
|
15
15
|
## 1.2.0 (31/05/2024)
|
16
16
|
|
17
17
|
* Added support for UNA segments. Special characters different from the defaults can now be used.
|
18
|
-
* Added una_special_characters method that returns just the special characters.
|
18
|
+
* Added `#una_special_characters` method that returns just the special characters.
|
19
|
+
|
20
|
+
## 1.2.1 (4/06/2024)
|
21
|
+
|
22
|
+
* `#una_special_characters` method now also returns decimal notation character, default `.`.
|
23
|
+
* `#una_special_characters` method can now take no arguments, and will return the default special characters if so.
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This gem parses EDIFACT or TRADACOMS input, and converts it into a ruby array st
|
|
4
4
|
|
5
5
|
It does not handle validation itself.
|
6
6
|
|
7
|
-
This gem is heavily inspired by and attempts to output similar results as [edifact_parser](https://github.com/pvdvreede/edifact_parser)
|
7
|
+
This gem is heavily inspired by and attempts to output similar results as [edifact_parser](https://github.com/pvdvreede/edifact_parser)
|
8
8
|
|
9
9
|
## Requirements
|
10
10
|
|
@@ -20,7 +20,7 @@ This gem has been tested on the following ruby versions:
|
|
20
20
|
In your `Gemfile`:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
gem 'edifact_rails', '~> 1.
|
23
|
+
gem 'edifact_rails', '~> 1.2'
|
24
24
|
```
|
25
25
|
|
26
26
|
Otherwise:
|
@@ -54,6 +54,7 @@ una_special_characters = EdifactRails.una_special_characters(your_string_input)
|
|
54
54
|
{
|
55
55
|
component_data_element_seperator: ":",
|
56
56
|
data_element_seperator: "+",
|
57
|
+
decimal_notation: ".",
|
57
58
|
escape_character: "?",
|
58
59
|
segment_seperator: "'"
|
59
60
|
}
|
data/lib/edifact_rails/parser.rb
CHANGED
@@ -20,7 +20,7 @@ module EdifactRails
|
|
20
20
|
string = treat_input(string)
|
21
21
|
|
22
22
|
# Split the input string into segments
|
23
|
-
segments = string.split(/(?<!#{@
|
23
|
+
segments = string.split(/(?<!#{Regexp.quote(@escape_character)})#{Regexp.quote(@segment_seperator)}/)
|
24
24
|
|
25
25
|
# Detect if the input is a tradacoms file
|
26
26
|
@is_tradacoms = segments.map { |s| s[3] }.uniq == ["="]
|
@@ -40,6 +40,7 @@ module EdifactRails
|
|
40
40
|
{
|
41
41
|
component_data_element_seperator: @component_data_element_seperator,
|
42
42
|
data_element_seperator: @data_element_seperator,
|
43
|
+
decimal_notation: @decimal_notation,
|
43
44
|
escape_character: @escape_character,
|
44
45
|
segment_seperator: @segment_seperator
|
45
46
|
}
|
@@ -51,20 +52,16 @@ module EdifactRails
|
|
51
52
|
component_data_element_seperator =
|
52
53
|
EdifactRails::DEFAULT_SPECIAL_CHARACTERS[:component_data_element_seperator],
|
53
54
|
data_element_seperator = EdifactRails::DEFAULT_SPECIAL_CHARACTERS[:data_element_seperator],
|
55
|
+
decimal_notation = EdifactRails::DEFAULT_SPECIAL_CHARACTERS[:decimal_notation],
|
54
56
|
escape_character = EdifactRails::DEFAULT_SPECIAL_CHARACTERS[:escape_character],
|
55
57
|
segment_seperator = EdifactRails::DEFAULT_SPECIAL_CHARACTERS[:segment_seperator]
|
56
58
|
)
|
57
59
|
# Set the special characters
|
58
60
|
@component_data_element_seperator = component_data_element_seperator
|
59
61
|
@data_element_seperator = data_element_seperator
|
62
|
+
@decimal_notation = decimal_notation
|
60
63
|
@escape_character = escape_character
|
61
64
|
@segment_seperator = segment_seperator
|
62
|
-
|
63
|
-
# Escape the special characters for use in regex later on
|
64
|
-
@component_data_element_separator_rx = Regexp.quote(@component_data_element_seperator)
|
65
|
-
@data_element_separator_rx = Regexp.quote(@data_element_seperator)
|
66
|
-
@escape_char_rx = Regexp.quote(@escape_character)
|
67
|
-
@segment_separator_rx = Regexp.quote(@segment_seperator)
|
68
65
|
end
|
69
66
|
|
70
67
|
def detect_special_characters(string)
|
@@ -82,7 +79,7 @@ module EdifactRails
|
|
82
79
|
# 4. Release character (aka escape character)
|
83
80
|
# 5. Reserved for future use, so always a space for now
|
84
81
|
# 6. Segment terminator
|
85
|
-
set_special_characters(string[3], string[4], string[6], string[8])
|
82
|
+
set_special_characters(string[3], string[4], string[5], string[6], string[8])
|
86
83
|
end
|
87
84
|
|
88
85
|
def treat_input(string)
|
@@ -112,7 +109,10 @@ module EdifactRails
|
|
112
109
|
#
|
113
110
|
# "LIN+even????+123" => '+' is not escaped, gsub'ed => "even???? +123" => parsed => ['LIN', ['even??'], [123]]
|
114
111
|
# "LIN+odd???+123" => '+' is escaped, not gsub'ed => "odd???+123" => parsed => ['LIN', ['odd?+123']]
|
115
|
-
string.gsub(
|
112
|
+
string.gsub(
|
113
|
+
/(?<!#{Regexp.quote(@escape_character)})((#{Regexp.quote(@escape_character)}{2})+)([#{other_specials_rx}])/,
|
114
|
+
'\1 \3'
|
115
|
+
)
|
116
116
|
end
|
117
117
|
|
118
118
|
# Split the segment into data elements, take the first as the tag, then parse the rest
|
@@ -123,7 +123,7 @@ module EdifactRails
|
|
123
123
|
segment[3] = @data_element_seperator if @is_tradacoms && segment.length >= 4
|
124
124
|
|
125
125
|
# Segments are made up of data elements
|
126
|
-
data_elements = segment.split(/(?<!#{@
|
126
|
+
data_elements = segment.split(/(?<!#{Regexp.quote(@escape_character)})#{Regexp.quote(@data_element_seperator)}/)
|
127
127
|
|
128
128
|
# The first element is the tag, pop it off
|
129
129
|
parsed_segment = []
|
@@ -136,7 +136,8 @@ module EdifactRails
|
|
136
136
|
# Split the data elements into component data elements, and treat them
|
137
137
|
def parse_data_element(element)
|
138
138
|
# Split data element into components
|
139
|
-
components =
|
139
|
+
components =
|
140
|
+
element.split(/(?<!#{Regexp.quote(@escape_character)})#{Regexp.quote(@component_data_element_seperator)}/)
|
140
141
|
|
141
142
|
components.map { |component| treat_component(component) }
|
142
143
|
end
|
@@ -156,7 +157,7 @@ module EdifactRails
|
|
156
157
|
|
157
158
|
# If the component has escaped characters in it, remove the escape character and return the character as is
|
158
159
|
# "?+" -> "+", "??" -> "?"
|
159
|
-
component.gsub!(/#{@
|
160
|
+
component.gsub!(/#{Regexp.quote(@escape_character)}([#{Regexp.quote(all_special_characters_string)}])/, '\1')
|
160
161
|
|
161
162
|
# Convert empty strings to nils
|
162
163
|
component = nil if component.empty?
|
data/lib/edifact_rails.rb
CHANGED
@@ -6,6 +6,7 @@ module EdifactRails
|
|
6
6
|
DEFAULT_SPECIAL_CHARACTERS = {
|
7
7
|
component_data_element_seperator: ":",
|
8
8
|
data_element_seperator: "+",
|
9
|
+
decimal_notation: ".",
|
9
10
|
escape_character: "?",
|
10
11
|
segment_seperator: "'"
|
11
12
|
}.freeze
|
@@ -19,7 +20,7 @@ module EdifactRails
|
|
19
20
|
parse(File.read(file_path).split("\n").join)
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.una_special_characters(string)
|
23
|
+
def self.una_special_characters(string = '')
|
23
24
|
parser = EdifactRails::Parser.new
|
24
25
|
parser.una_special_characters(string)
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edifact_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Blackwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|