projects
/
working
/
random.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2866b76
)
Added String#chunk_and_group to make adding text to CDEs more straightforward
author
Michael B. Klein
<mbklein@gmail.com>
Mon, 23 Aug 2010 23:20:48 +0000
(16:20 -0700)
committer
Michael B. Klein
<mbklein@gmail.com>
Mon, 23 Aug 2010 23:20:48 +0000
(16:20 -0700)
lib/edi/mapper.rb
patch
|
blob
|
history
diff --git
a/lib/edi/mapper.rb
b/lib/edi/mapper.rb
index
b3b831f
..
387eaa5
100644
(file)
--- 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