Class: Fragile::Plugin::SortFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/fragile/plugin/sort_filter.rb

Overview

Examples:

pipeline :sample do
  use "direct_input", :data => [2, 1, 4, 3, 5]
  use "sort_filter", :proc => ->(x, y){ x <=> y }
  use "console_output"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SortFilter

Returns a new instance of SortFilter.



14
15
16
# File 'lib/fragile/plugin/sort_filter.rb', line 14

def initialize(options={})
  @proc = options[:proc]
end

Instance Attribute Details

#procObject (readonly)

Returns the value of attribute proc.



12
13
14
# File 'lib/fragile/plugin/sort_filter.rb', line 12

def proc
  @proc
end

Instance Method Details

#call(data) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fragile/plugin/sort_filter.rb', line 18

def call(data)
  if @proc
    data.sort do |x, y|
      @proc.call(x, y)
    end
  else
    data
  end
end