Class: ArrayUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/web_translate_it/util/array_util.rb

Class Method Summary collapse

Class Method Details

.chunk(arr, pieces = 2) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/web_translate_it/util/array_util.rb', line 6

def self.chunk(arr, pieces=2)
  len = arr.length;
  mid = (len/pieces)
  chunks = []
  start = 0
  1.upto(pieces) do |i|
    last = start+mid
    last = last-1 unless len%pieces >= i
    chunks << arr[start..last] || []
    start = last+1
  end
  chunks
end

.to_columns(arr) ⇒ Object


2
3
4
# File 'lib/web_translate_it/util/array_util.rb', line 2

def self.to_columns(arr)
  " #{StringUtil.backward_truncate(arr[0])} | #{arr[1]}  #{arr[2]}\n"
end