class EDI::A::MsgGroup
Class EDI::A::MsgGroup
This class implements a group of business documents of the same type Its header unites features from UNB as well as from UNH.
Attributes
Public Class Methods
Creates an empty ANSI X12 message group (functional group) Don’t use directly - use new_msggroup
of class Interchange
instead!
First parameter¶ ↑
This is always the parent object (an interchange object). Use method new_msggroup
in the corresponding object instead of creating message groups unattended - the parent reference will be accounted for automatically.
Second parameter¶ ↑
List of supported hash keys:
GS presets for your convenience, may be changed later¶ ↑
- :msg_type
-
(for ST), default = ‘837’
- :func_ident
-
Sets
DE
479, default = ‘HC’ - :version
-
Merges into
DE
480, default = ‘004’ - :release
-
Merges into
DE
480, default = ‘01’ - :sub_version
-
Merges into
DE
480, default = ‘0’
Optional parameters, required depending upon use case¶ ↑
- :assigned_code
-
Merges into
DE
480 (subset), default = nil - :sender
-
Presets
DE
142, default = nil - :recipient
-
Presets
DE
124, default = nil - :group_reference
-
Presets
DE
28, auto-incremented
Notes¶ ↑
-
The functional group control number in GS and GE (28) is set automatically to a number that is unique for this message group and the running process (auto-increment).
-
The counter in GE (97) is set automatically to the number of included messages.
-
The trailer segment (GE) is generated automatically.
-
Whenever possible, avoid writing to the counters of the message header or trailer segments!
EDI::MsgGroup::new
# File lib/edi4r/ansi_x12.rb, line 410 def initialize( p, user_par={} ) super( p, user_par ) @messages_created = 0 if user_par.is_a? Hash preset_group( user_par ) @header = new_segment('GS') @trailer = new_segment('GE') @trailer.d97 = 0 @header.d479 = @func_ident # @name @header.d455 = @resp_agency @header.d480 = @version+@release+@sub_version #cde.d0054 = @release #cde.d0057 = @subset @header.d142 = user_par[:sender] || root.header.dI06 @header.d124 = user_par[:recipient] || root.header.dI07 @header.d28 = user_par[:group_reference] || p.groups_created # @trailer.d28 = @header.d28 @header.d455 = 'X' t = Time.now @header.d373 = t.strftime('%Y%m%d') @header.d337 = t.strftime("%H%M") elsif user_par.is_a? Segment @header = user_par raise "GS expected, #{@header.name} found!" if @header.name != 'GS' @header.parent = self @header.root = self.root # Assign a temporary GS segment de_sep = root.de_sep @trailer = Segment.parse(root, 'GE' << de_sep << '0' << de_sep << '0') @name = @header.d479 # FIXME: HC?? s480 = @header.d480 @version = s480[0,3] @release = s480[3,2] @sub_version = s480[5,1] # @subset = s008.d0057 @resp_agency = @header.d455 else raise "First parameter: Illegal type!" end end
# File lib/edi4r/ansi_x12.rb, line 483 def MsgGroup.parse (p, segment_list) # List of segments grp = p.new_msggroup(:msg_type => 'DUMMY') # We now expect a sequence of segments that comprises one group, # starting with ST and ending with SE, and with messages in between. # We process the ST/SE envelope separately, then work on the content. header = grp.parse_segment(segment_list.shift, 'GS') trailer = grp.parse_segment(segment_list.pop, 'GE') init_seg = Regexp.new('^ST') exit_seg = Regexp.new('^SE') while segbuf = segment_list.shift case segbuf when init_seg sub_list = Array.new sub_list.push segbuf when exit_seg sub_list.push segbuf grp.add grp.parse_message(sub_list) else sub_list.push segbuf end end grp.header = header grp.trailer = trailer grp end
Public Instance Methods
EDI::MsgGroup#add
# File lib/edi4r/ansi_x12.rb, line 537 def add( msg, auto_validate=true ) super( msg ) @trailer.d97 = @trailer.d97.to_i if @trailer.d97.is_a? String @trailer.d97 += 1 end
# File lib/edi4r/ansi_x12.rb, line 518 def new_message(params={}) @messages_created += 1 Message.new(self, params) end
EDI::Collection_HT#to_s
# File lib/edi4r/ansi_x12.rb, line 544 def to_s postfix = '' << root.seg_term << root.e_linebreak super( postfix ) end
EDI::Collection_HT#validate
# File lib/edi4r/ansi_x12.rb, line 550 def validate( err_count=0 ) # Consistency checks if (a=@trailer.d97) != (b=self.size) EDI::logger.warn "GE: DE 97 (#{a}) does not match number of messages (#{b})" err_count += 1 end a, b = @trailer.d28, @header.d28 if a != b EDI::logger.warn "GE: DE 28 (#{a}) does not match reference in GS (#{b})" err_count += 1 end # FIXME: Check if messages are uniquely numbered super end