Class: Cursed::Adapter::Array

Inherits:
Base
  • Object
show all
Defined in:
lib/cursed/adapter/array.rb

Instance Attribute Summary

Attributes inherited from Base

#relation

Instance Method Summary collapse

Methods inherited from Base

#apply_to, #initialize

Constructor Details

This class inherits a constructor from Cursed::Adapter::Base

Instance Method Details

#after(attribute, value) ⇒ Object



19
20
21
# File 'lib/cursed/adapter/array.rb', line 19

def after(attribute, value)
  relation.select! { |x| x.public_send(attribute) > value }
end

#ascend_by(attribute) ⇒ Object



11
12
13
# File 'lib/cursed/adapter/array.rb', line 11

def ascend_by(attribute)
  relation.sort_by!(&attribute)
end

#before(attribute, value) ⇒ Object



23
24
25
# File 'lib/cursed/adapter/array.rb', line 23

def before(attribute, value)
  relation.select! { |x| x.public_send(attribute) < value }
end

#descend_by(attribute) ⇒ Object



6
7
8
9
# File 'lib/cursed/adapter/array.rb', line 6

def descend_by(attribute)
  relation.sort_by!(&attribute)
  relation.reverse!
end

#limit(count) ⇒ Object



15
16
17
# File 'lib/cursed/adapter/array.rb', line 15

def limit(count)
  @relation = relation.take(count)
end