class Array

Public Instance Methods

cama_pluck(attribute) click to toggle source

alternative pluck method for arrays

# File lib/ext/array.rb, line 52
def cama_pluck(attribute)
  map { |i| i.send(attribute) }
end
clean_empty() click to toggle source

delete empty values

# File lib/ext/array.rb, line 3
def clean_empty
  delete_if(&:blank?)
  self
end
delete_item(item) click to toggle source
# File lib/ext/array.rb, line 14
def delete_item(item)
  delete_if { |a| a.to_s == item.to_s }
end
delete_items(items) click to toggle source

remove all item from array

# File lib/ext/array.rb, line 19
def delete_items(items)
  items = items.to_s_
  delete_if { |a| items.include?(a.to_s) }
end
delete_last() click to toggle source

delete last item

# File lib/ext/array.rb, line 38
def delete_last
  slice(0, size - 1)
end
fix_in_sql(def_val = -1) click to toggle source

add default value if array is empty

# File lib/ext/array.rb, line 9
def fix_in_sql(def_val = -1)
  self << def_val if empty?
  self
end
join_bar() click to toggle source
# File lib/ext/array.rb, line 47
def join_bar
  uniq.map { |us_id| "__#{us_id}__" }.join(',')
end
join_pluck() click to toggle source

join pluck arrays

# File lib/ext/array.rb, line 43
def join_pluck
  collect { |row| row[1].present? ? row.join(',') : row[0] }.join(',').to_s.split(',')
end
strip() click to toggle source
# File lib/ext/array.rb, line 28
def strip
  collect { |i| i.to_s.strip }
end
to_i() click to toggle source
# File lib/ext/array.rb, line 24
def to_i
  collect(&:to_i)
end
to_s_() click to toggle source

convert all items to string

# File lib/ext/array.rb, line 33
def to_s_
  collect(&:to_s)
end
translate(locale = nil) click to toggle source

translate array values return the same array translated

# File lib/ext/translator.rb, line 78
def translate(locale = nil)
  collect do |val|
    val.to_s.translate(locale)
  end
end