Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/edi/mapper.rb

Instance Method Summary collapse

Instance Method Details

#chunk(len) ⇒ Object



18
19
20
21
# File 'lib/edi/mapper.rb', line 18

def chunk(len)
  re = Regexp.new(".{0,#{len.to_i}}")
  self.scan(re).flatten.reject { |chunk| chunk.nil? or chunk.empty? }
end

#chunk_and_group(chunk_len, group_len) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/edi/mapper.rb', line 23

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