class Array

Add some tools to Array to make parsing spreadsheet rows easier.

Public Instance Methods

downcase() click to toggle source
# File lib/allplayers_imports.rb, line 34
def downcase
  arr = []
  self.each do |item|
    arr.push(item.downcase)
  end
  arr
end
gsub(pattern,replacement) click to toggle source
# File lib/allplayers_imports.rb, line 41
def gsub(pattern,replacement)
  arr = []
  self.each do |item|
    arr.push(item.gsub(pattern,replacement))
  end
  arr
end
split_first(pattern) click to toggle source

Split off first element in each array item, after splitting by pattern, then strip trailing and preceding whitespaces.

# File lib/allplayers_imports.rb, line 27
def split_first(pattern)
  arr = []
  self.each do | item |
    arr.push(item.split(pattern)[0].strip)
  end
  arr
end
to_hash(other) click to toggle source

Little utility to convert array to Hash with defined keys.

# File lib/allplayers_imports.rb, line 22
def to_hash(other)
  Hash[ *(0...other.size()).inject([]) { |arr, ix| arr.push(other[ix], self[ix]) } ]
end