Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/generators/leolay/templates/lib/upd_array.rb
Instance Method Summary collapse
-
#item(options = {}) ⇒ Object
Find in collection where :search condition is matched and return a fields if param :get is passed otherwise it return the item Example1 Articles.quickly :search => => 1, :get => :title Example2 People.quickly :search => => ABCDFG01H02I100J.
Instance Method Details
#item(options = {}) ⇒ Object
Find in collection where :search condition is matched and return a fields if param :get is passed otherwise it return the item Example1 Articles.quickly :search => => 1, :get => :title Example2 People.quickly :search => => ABCDFG01H02I100J
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/leolay/templates/lib/upd_array.rb', line 6 def item(={}) #:search => {:id => 3} #:get => :name = { :search => nil, :get => nil }.merge() raise "Array.trova: specify required parameters!" unless [:search] self.each do |item| condition = nil [:search].each do |label, value| condition = (item[label] == value) break unless condition end next unless condition return ([:get] ? item[[:get]] : item) end nil end |