From 9c27e8f59b9e4e7c2769917ce0614153c1c7501f Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Mon, 23 Aug 2010 16:20:48 -0700 Subject: [PATCH] Added String#chunk_and_group to make adding text to CDEs more straightforward --- lib/edi/mapper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/edi/mapper.rb b/lib/edi/mapper.rb index b3b831f84..387eaa541 100644 --- a/lib/edi/mapper.rb +++ b/lib/edi/mapper.rb @@ -15,6 +15,18 @@ class String self.scan(re).flatten.reject { |chunk| chunk.nil? or chunk.empty? } end + def chunk_and_group(chunk_len, group_len) + chunks = self.chunk(chunk_len) + groups = [[]] + chunks.each { |chunk| + if groups.last.length == group_len + groups << [] + end + groups.last << chunk + } + groups + end + end module EDI::E -- 2.11.0