Class: Pocolog::Upgrade::Ops::Sequence

Inherits:
Base
  • Object
show all
Defined in:
lib/pocolog/upgrade/ops/sequence.rb

Overview

A class that applies a list of operations in sequence

Instance Attribute Summary collapse

Attributes inherited from Base

#to_type

Instance Method Summary collapse

Methods inherited from Base

#call, #identity?

Constructor Details

#initialize(ops, to_type) ⇒ Sequence

Returns a new instance of Sequence



9
10
11
12
13
14
# File 'lib/pocolog/upgrade/ops/sequence.rb', line 9

def initialize(ops, to_type)
    super(to_type)
    @ops = ops.map do |op|
        [op, op.to_type.new]
    end
end

Instance Attribute Details

#opsObject (readonly)

The operations to apply, along with their intermdiate values



7
8
9
# File 'lib/pocolog/upgrade/ops/sequence.rb', line 7

def ops
  @ops
end

Instance Method Details

#convert(value) ⇒ Object



16
17
18
19
20
21
# File 'lib/pocolog/upgrade/ops/sequence.rb', line 16

def convert(value)
    ops.inject(value) do |v, (op, op_value)|
        op.call(op_value, v)
        op_value
    end
end