lib/eancom/edifact/segment.rb in eancom-1.6.3 vs lib/eancom/edifact/segment.rb in eancom-2.0.0
- old
+ new
@@ -9,22 +9,25 @@
@tag = tag
validate_structure
end
def self.initialize_by_components(structure, array)
- 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 \
+ 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 \
'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
@@ -34,14 +37,13 @@
def structure
@structure ||= Eancom.find_structure(tag: tag)
end
def to_s
- string = array.map do |e|
+ 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
@@ -78,13 +80,9 @@
def tag?(other)
tag == other
end
def starts_message?
- false
- end
-
- def starts_location?
false
end
def starts_item?
false