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

$Id: Loop.rb 59 2009-03-19 22:32:13Z 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:       if self.has_content?
67:         self.to_a.inject(''){|loop_str, i|
68:           loop_str += i.nodes.inject(''){|nodes_str, j|
69:             nodes_str += j.render
70:           } 
71:         }
72:       else
73:         ''
74:       end
75:     end