Class: Alf::Engine::Sort::InMemory
- Inherits:
-
Object
- Object
- Alf::Engine::Sort::InMemory
- Includes:
- Cog, Alf::Engine::Sort
- Defined in:
- lib/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"},
# ]
Constant Summary
Constants included from Cog
Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS
Instance Attribute Summary collapse
-
#operand ⇒ Enumerable
readonly
The operand.
-
#ordering ⇒ Ordering
readonly
The ordering info.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each(&block) ⇒ Object
- #arguments ⇒ Object
- #cog_orders ⇒ Object
-
#initialize(operand, ordering, expr = nil, compiler = nil) ⇒ InMemory
constructor
Creates an Autonum instance.
Methods included from Cog
#children, #each, #options, #to_s
Methods included from Compiler::Cog
#orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation
Methods included from Alf::Engine::Sort
Constructor Details
#initialize(operand, ordering, expr = nil, compiler = nil) ⇒ InMemory
Creates an Autonum instance
29 30 31 32 33 |
# File 'lib/alf/engine/sort/in_memory.rb', line 29 def initialize(operand, ordering, expr = nil, compiler = nil) super(expr, compiler) @operand = operand @ordering = ordering end |
Instance Attribute Details
#operand ⇒ Enumerable (readonly)
Returns The operand.
23 24 25 |
# File 'lib/alf/engine/sort/in_memory.rb', line 23 def operand @operand end |
#ordering ⇒ Ordering (readonly)
Returns The ordering info.
26 27 28 |
# File 'lib/alf/engine/sort/in_memory.rb', line 26 def ordering @ordering end |
Instance Method Details
#_each(&block) ⇒ Object
41 42 43 |
# File 'lib/alf/engine/sort/in_memory.rb', line 41 def _each(&block) operand.to_a.sort!(&ordering.sorter).each(&block) end |
#arguments ⇒ Object
45 46 47 |
# File 'lib/alf/engine/sort/in_memory.rb', line 45 def arguments [ ordering ] end |
#cog_orders ⇒ Object
36 37 38 |
# File 'lib/alf/engine/sort/in_memory.rb', line 36 def cog_orders @cog_orders ||= [ ordering ] end |