Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/ext/array.rb,
lib/ext/translator.rb
Instance Method Summary collapse
-
#cama_pluck(attribute) ⇒ Object
alternative pluck method for arrays.
-
#clean_empty ⇒ Object
delete empty values.
- #delete_item(item) ⇒ Object
-
#delete_items(items) ⇒ Object
remove all item from array.
-
#delete_last ⇒ Object
delete last item.
-
#fix_in_sql(def_val = -1)) ⇒ Object
add default value if array is empty.
- #join_bar ⇒ Object
-
#join_pluck ⇒ Object
join pluck arrays.
- #strip ⇒ Object
- #to_i ⇒ Object
-
#to_s_ ⇒ Object
convert all items to string.
-
#translate(locale = nil) ⇒ Object
translate array values return the same array translated.
Instance Method Details
#cama_pluck(attribute) ⇒ Object
alternative pluck method for arrays
55 56 57 |
# File 'lib/ext/array.rb', line 55 def cama_pluck(attribute) self.map{|i| i.send(attribute) } end |
#clean_empty ⇒ Object
delete empty values
3 4 5 6 |
# File 'lib/ext/array.rb', line 3 def clean_empty self.delete_if {|v| v.blank? } self end |
#delete_item(item) ⇒ Object
14 15 16 |
# 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) ⇒ 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_ self.delete_if { |a| items.include?(a.to_s) } end |
#delete_last ⇒ Object
delete last item
41 42 43 |
# File 'lib/ext/array.rb', line 41 def delete_last self.slice(0, self.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 self.empty? self end |
#join_bar ⇒ Object
50 51 52 |
# File 'lib/ext/array.rb', line 50 def self.uniq.map{|us_id| "__#{us_id}__"}.join(',') end |
#join_pluck ⇒ Object
join pluck arrays
46 47 48 |
# 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 ⇒ Object
29 30 31 32 |
# File 'lib/ext/array.rb', line 29 def strip a = self.collect{|i| i.to_s.strip} a end |
#to_i ⇒ Object
24 25 26 27 |
# File 'lib/ext/array.rb', line 24 def to_i a = self.collect{|i| i.to_i} a end |
#to_s_ ⇒ Object
convert all items to string
35 36 37 38 |
# File 'lib/ext/array.rb', line 35 def to_s_ a = self.collect{|i| i.to_s} a end |
#translate(locale = nil) ⇒ Object
translate array values return the same array translated
79 80 81 82 83 |
# File 'lib/ext/translator.rb', line 79 def translate(locale = nil) self.collect do |val| val.to_s.translate(locale) end end |