Class: TextRecord::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/text_record/collection.rb

Instance Method Summary collapse

Instance Method Details

#order(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/text_record/collection.rb', line 12

def order(options)
  attribute = options.keys.first
  order = options[attribute]
  
  sort do |object1, object2|
    comp = object1.send(attribute) <=> object2.send(attribute)
    comp = (order == :asc) ? comp : comp * -1
    comp
  end
end

#where(options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/text_record/collection.rb', line 3

def where(options = {})      
  select do |object|
    options.keys.inject(true) do |flag, attribute|
      object.send(attribute).eql?(options[attribute]) && flag
    end
  end
end