Class: Fall::RecordOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/fall/record_operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(func) ⇒ RecordOperation

Returns a new instance of RecordOperation.



25
26
27
# File 'lib/fall/record_operation.rb', line 25

def initialize(func)
  @func = func
end

Instance Attribute Details

#funcObject (readonly)

Returns the value of attribute func.



3
4
5
# File 'lib/fall/record_operation.rb', line 3

def func
  @func
end

Class Method Details

.from_code(code) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fall/record_operation.rb', line 5

def self.from_code(code)
  func = instance_eval "    lambda do |record|\n      return record if record.discard?\n\n      result = Record.wrap(record.instance_eval { [\#{code}] })\n\n     filtered = result.zip(record).reject { _1.size != 2 }.map do |result, original_record|\n                     case result\n                     in true then original_record\n                     in false then :__discard\n                     else result\n                    end\n                  end \n     Record.wrap(filtered)\n     end\n  RUBY\n  new(func)\nend\n"

Instance Method Details

#add_to_pipeline(pipeline) ⇒ Object



29
30
31
# File 'lib/fall/record_operation.rb', line 29

def add_to_pipeline(pipeline)
  pipeline.add_record_operation(self)
end

#call(record) ⇒ Object



33
34
35
# File 'lib/fall/record_operation.rb', line 33

def call(record)
  @func.call(record)
end

#chain(operation) ⇒ Object Also known as: >>



37
38
39
40
41
42
# File 'lib/fall/record_operation.rb', line 37

def chain(operation)
  identity = ->(i) { i }

  composed = (func >> (operation.func >> identity))
  self.class.new(composed)
end

#to_procObject



46
47
48
# File 'lib/fall/record_operation.rb', line 46

def to_proc
  @func
end