Class X12::Loop
In: lib/X12/Loop.rb
Parent: Base

$Id: Loop.rb 35 2008-11-13 18:33:44Z ikk $

Implements nested loops of segments

Methods

parse   render  

Public Instance methods

Parse a string and fill out internal structures with the pieces of it. Returns an unparsed portion of the string or the original string if nothing was parsed out.

[Source]

    # File lib/X12/Loop.rb, line 47
47:     def parse(str)
48:       #puts "Parsing loop #{name}: "+str
49:       s = str
50:       nodes.each{|i|
51:         m = i.parse(s)
52:         s = m if m
53:       } 
54:       if str == s
55:         return nil
56:       else
57:         self.parsed_str = str[0..-s.length-1]
58:         s = do_repeats(s)
59:       end
60:       #puts 'Parsed loop '+self.inspect
61:       return s
62:     end

Render all components of this loop as string suitable for EDI

[Source]

    # File lib/X12/Loop.rb, line 65
65:     def render
66:       self.to_a.inject(''){|loop_str, i|
67:         loop_str += i.nodes.inject(''){|nodes_str, j|
68:           nodes_str += j.render
69:         } 
70:       }
71:     end