Class: String

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

Instance Method Summary collapse

Instance Method Details

#chunk(len) ⇒ Object



13
14
15
16
# File 'lib/edi/mapper.rb', line 13

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/edi/mapper.rb', line 18

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