Class: Alf::Engine::Sort::InMemory
- Inherits:
-
Object
- Object
- Alf::Engine::Sort::InMemory
- Includes:
- Cog
- Defined in:
- lib/alf-engine/alf/engine/sort/in_memory.rb
Overview
Implement an in-memory sort, relying on ‘to_a.sort!`
Example:
rel = [
{:name => "Smith"},
{:name => "Jones"}
]
Sort.new(rel, Ordering[[:name, :asc]]).to_a
# => [
# {:name => "Jones"}
# {:name => "Smith"},
# ]
Instance Attribute Summary collapse
-
#operand ⇒ Enumerable
readonly
The operand.
-
#ordering ⇒ Ordering
readonly
The ordering info.
Instance Method Summary collapse
- #_each(&block) ⇒ Object
-
#initialize(operand, ordering) ⇒ InMemory
constructor
Creates an Autonum instance.
Methods included from Cog
Constructor Details
#initialize(operand, ordering) ⇒ InMemory
Creates an Autonum instance
28 29 30 31 |
# File 'lib/alf-engine/alf/engine/sort/in_memory.rb', line 28 def initialize(operand, ordering) @operand = operand @ordering = ordering end |
Instance Attribute Details
#operand ⇒ Enumerable (readonly)
Returns The operand.
22 23 24 |
# File 'lib/alf-engine/alf/engine/sort/in_memory.rb', line 22 def operand @operand end |
#ordering ⇒ Ordering (readonly)
Returns The ordering info.
25 26 27 |
# File 'lib/alf-engine/alf/engine/sort/in_memory.rb', line 25 def ordering @ordering end |
Instance Method Details
#_each(&block) ⇒ Object
34 35 36 |
# File 'lib/alf-engine/alf/engine/sort/in_memory.rb', line 34 def _each(&block) operand.to_a.sort!(&ordering.sorter).each(&block) end |