lib/eancom/edifact/segment.rb in eancom-1.5.5 vs lib/eancom/edifact/segment.rb in eancom-1.5.6
- old
+ new
@@ -9,25 +9,22 @@
@tag = tag
validate_structure
end
def self.initialize_by_components(structure, array)
- begin
- new(structure.build_hash(array))
- rescue StandardError => e
- raise SegmentParserError.new(
- "'Parser Error in structure #{structure.tag} with array #{array}.\n \
- 'Inside Structure: \n \ '#{structure.to_s}.\n \
+ new(**structure.build_hash(array))
+ rescue StandardError => e
+ raise SegmentParserError, "'Parser Error in structure #{structure.tag} with array #{array}.\n \
+ 'Inside Structure: \n \ '#{structure}.\n \
'Error:\n \
'#{e}"
- )
- end
end
def validate_structure
attributes.each do |key, value|
next if value.nil?
+
structure.validate!(key, value)
end
end
def array
@@ -40,9 +37,10 @@
def to_s
string = array.map do |e|
e = e.compact
next if e.empty?
+
[e.join(component_delimiter)]
end.join(data_delimiter)
clean_end_string(string)
string << segment_delimiter
string