Class: X12::Loop
Overview
$Id: Loop.rb 59 2009-03-19 22:32:13Z ikk $
Implements nested loops of segments
Instance Attribute Summary
Attributes inherited from Base
#composite_separator, #field_separator, #name, #next_repeat, #nodes, #parsed_str, #repeats, #segment_separator
Instance Method Summary collapse
- #each ⇒ Object
-
#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.
Methods inherited from Base
#[], #do_repeats, #dup, #find, #has_content?, #initialize, #inspect, #method_missing, #repeat, #set_empty!, #show, #size, #to_a, #to_s, #with
Constructor Details
This class inherits a constructor from X12::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class X12::Base
Instance Method Details
#each ⇒ Object
78 79 80 81 82 83 |
# File 'lib/x12/loop.rb', line 78 def each res = self.to_a 0.upto(res.length - 1) do |x| yield res[x] end end |
#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 |