class Array

Public Instance Methods

cama_pluck(attribute) click to toggle source

alternative pluck method for arrays

# File lib/ext/array.rb, line 55
def cama_pluck(attribute)
  self.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
  self.delete_if {|v| v.blank? }
  self
end
delete_item(item) click to toggle source
# File lib/ext/array.rb, line 14
def delete_item(item)
  self.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_
  self.delete_if { |a| items.include?(a.to_s) }
end
delete_last() click to toggle source

delete last item

# File lib/ext/array.rb, line 41
def delete_last
  self.slice(0, self.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 self.empty?
  self
end
join_bar() click to toggle source
# File lib/ext/array.rb, line 50
def join_bar
  self.uniq.map{|us_id| "__#{us_id}__"}.join(',')
end
join_pluck() click to toggle source

join pluck arrays

# File lib/ext/array.rb, line 46
def join_pluck
  self.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 29
def strip
  a = self.collect{|i| i.to_s.strip}
  a
end
to_i() click to toggle source
# File lib/ext/array.rb, line 24
def to_i
  a = self.collect{|i| i.to_i}
  a
end
to_s_() click to toggle source

convert all items to string

# File lib/ext/array.rb, line 35
def to_s_
  a = self.collect{|i| i.to_s}
  a
end
translate(locale = nil) click to toggle source

translate array values return the same array translated

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