Class: OptionLab::Models::ArrayInputs

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/option_lab/models.rb

Overview

Array inputs model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ArrayInputs

Returns a new instance of ArrayInputs.



578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/option_lab/models.rb', line 578

def initialize(attributes = {})
  # Set defaults
  @model = 'array'

  super(attributes)

  # Convert array to Numo::DFloat
  if @array.is_a?(Array)
    @array = Numo::DFloat.cast(@array)
  end

  validate!
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



576
577
578
# File 'lib/option_lab/models.rb', line 576

def array
  @array
end

#modelObject

Returns the value of attribute model.



576
577
578
# File 'lib/option_lab/models.rb', line 576

def model
  @model
end

Instance Method Details

#validate!Object

Raises:

  • (ArgumentError)


592
593
594
595
# File 'lib/option_lab/models.rb', line 592

def validate!
  raise ArgumentError, "model must be 'array'" unless model == 'array'
  raise ArgumentError, 'The array is empty!' if array.empty?
end