Class: X12::Loop
- Inherits:
-
Base
- Object
- Base
- X12::Loop
- Defined in:
- lib/X12/Loop.rb
Overview
$Id: Loop.rb 59 2009-03-19 22:32:13Z ikk $
Implements nested loops of segments
Instance Method Summary collapse
-
#parse(str) ⇒ Object
Parse a string and fill out internal structures with the pieces of it.
-
#render ⇒ Object
Render all components of this loop as string suitable for EDI.
Instance Method Details
#parse(str) ⇒ Object
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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/X12/Loop.rb', line 47 def parse(str) #puts "Parsing loop #{name}: "+str s = str nodes.each{|i| m = i.parse(s) s = m if m } if str == s return nil else self.parsed_str = str[0..-s.length-1] s = do_repeats(s) end #puts 'Parsed loop '+self.inspect return s end |
#render ⇒ Object
Render all components of this loop as string suitable for EDI
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/X12/Loop.rb', line 65 def render if self.has_content? self.to_a.inject(''){|loop_str, i| loop_str += i.nodes.inject(''){|nodes_str, j| nodes_str += j.render } } else '' end end |