Class: Locomotive::Steam::Adapters::Memory::Order
- Inherits:
-
Object
- Object
- Locomotive::Steam::Adapters::Memory::Order
show all
- Defined in:
- lib/locomotive/steam/adapters/memory/order.rb
Defined Under Namespace
Classes: Asc, Desc, Direction
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*spec) ⇒ Order
Returns a new instance of Order.
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/locomotive/steam/adapters/memory/order.rb', line 9
def initialize(*spec)
@list = []
spec.compact.each do |criterion|
@list += (case criterion
when Array then criterion
when Hash then criterion.to_a
when String then criterion.split(',').collect { |s| build(s.strip) }
else []
end)
end
end
|
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
7
8
9
|
# File 'lib/locomotive/steam/adapters/memory/order.rb', line 7
def list
@list
end
|
Instance Method Details
#apply_to(entry, locale) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/locomotive/steam/adapters/memory/order.rb', line 25
def apply_to(entry, locale)
@list.collect do |(name, direction)|
value = entry.send(name)
if value.respond_to?(:translations) value = value[locale]
end
asc?(direction) ? Asc.new(value) : Desc.new(value)
end
end
|
#asc?(direction) ⇒ Boolean
37
38
39
|
# File 'lib/locomotive/steam/adapters/memory/order.rb', line 37
def asc?(direction)
direction.nil? || direction.to_sym == :asc
end
|
#empty? ⇒ Boolean
21
22
23
|
# File 'lib/locomotive/steam/adapters/memory/order.rb', line 21
def empty?
@list.empty?
end
|