Class: Alf::Engine::Sort::InMemory

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

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

#operandEnumerable (readonly)

Returns The operand.

Returns:

  • (Enumerable)

    The operand



22
23
24
# File 'lib/alf-engine/alf/engine/sort/in_memory.rb', line 22

def operand
  @operand
end

#orderingOrdering (readonly)

Returns The ordering info.

Returns:

  • (Ordering)

    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