Class: Pocolog::Upgrade::Ops::ArrayCast

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

Overview

Converts to an array

Instance Attribute Summary collapse

Attributes inherited from Base

#to_type

Instance Method Summary collapse

Methods inherited from Base

#convert, #identity?

Constructor Details

#initialize(to_type, element_ops) ⇒ ArrayCast

Returns a new instance of ArrayCast



8
9
10
11
# File 'lib/pocolog/upgrade/ops/array_cast.rb', line 8

def initialize(to_type, element_ops)
    super(to_type)
    @element_ops = element_ops
end

Instance Attribute Details

#element_opsObject (readonly)

Returns the value of attribute element_ops



6
7
8
# File 'lib/pocolog/upgrade/ops/array_cast.rb', line 6

def element_ops
  @element_ops
end

Instance Method Details

#call(target, value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pocolog/upgrade/ops/array_cast.rb', line 13

def call(target, value)
    if value.size != to_type.length
        raise ArraySizeMismatch, "attempting to copy a container of size #{value.size} into an array of size #{to_type.length}"
    end

    i = 0
    value.raw_each do |sample|
        element_ops.call(target.raw_get(i), sample)
        i += 1
    end
end