Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/array.rb,
lib/ext/translator.rb

Instance Method Summary collapse

Instance Method Details

#cama_pluck(attribute) ⇒ Object

alternative pluck method for arrays



52
53
54
# File 'lib/ext/array.rb', line 52

def cama_pluck(attribute)
  map { |i| i.send(attribute) }
end

#clean_emptyObject

delete empty values



3
4
5
6
# File 'lib/ext/array.rb', line 3

def clean_empty
  delete_if(&:blank?)
  self
end

#delete_item(item) ⇒ Object



14
15
16
# File 'lib/ext/array.rb', line 14

def delete_item(item)
  delete_if { |a| a.to_s == item.to_s }
end

#delete_items(items) ⇒ Object

remove all item from array



19
20
21
22
# 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_lastObject

delete last item



38
39
40
# File 'lib/ext/array.rb', line 38

def delete_last
  slice(0, size - 1)
end

#fix_in_sql(def_val = -1)) ⇒ Object

add default value if array is empty



9
10
11
12
# File 'lib/ext/array.rb', line 9

def fix_in_sql(def_val = -1)
  self << def_val if empty?
  self
end

#join_barObject



47
48
49
# File 'lib/ext/array.rb', line 47

def join_bar
  uniq.map { |us_id| "__#{us_id}__" }.join(',')
end

#join_pluckObject

join pluck arrays



43
44
45
# File 'lib/ext/array.rb', line 43

def join_pluck
  collect { |row| row[1].present? ? row.join(',') : row[0] }.join(',').to_s.split(',')
end

#stripObject



28
29
30
# File 'lib/ext/array.rb', line 28

def strip
  collect { |i| i.to_s.strip }
end

#to_iObject



24
25
26
# File 'lib/ext/array.rb', line 24

def to_i
  collect(&:to_i)
end

#to_s_Object

convert all items to string



33
34
35
# File 'lib/ext/array.rb', line 33

def to_s_
  collect(&:to_s)
end

#translate(locale = nil) ⇒ Object

translate array values return the same array translated



78
79
80
81
82
# File 'lib/ext/translator.rb', line 78

def translate(locale = nil)
  collect do |val|
    val.to_s.translate(locale)
  end
end