From: Michael B. Klein Date: Mon, 23 Aug 2010 23:20:48 +0000 (-0700) Subject: Added String#chunk_and_group to make adding text to CDEs more straightforward X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9c27e8f59b9e4e7c2769917ce0614153c1c7501f;p=working%2Frandom.git Added String#chunk_and_group to make adding text to CDEs more straightforward --- 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