Class: OptionLab::Models::Stock

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

Overview

Stock position model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Stock

Returns a new instance of Stock.



36
37
38
39
# File 'lib/option_lab/models.rb', line 36

def initialize(attributes = {})
  @type = 'stock'
  super(attributes)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



33
34
35
# File 'lib/option_lab/models.rb', line 33

def action
  @action
end

#nObject

Returns the value of attribute n.



33
34
35
# File 'lib/option_lab/models.rb', line 33

def n
  @n
end

#prev_posObject

Returns the value of attribute prev_pos.



33
34
35
# File 'lib/option_lab/models.rb', line 33

def prev_pos
  @prev_pos
end

#typeObject (readonly)

Returns the value of attribute type.



34
35
36
# File 'lib/option_lab/models.rb', line 34

def type
  @type
end

Instance Method Details

#validate!Object

Raises:

  • (ArgumentError)


41
42
43
44
# File 'lib/option_lab/models.rb', line 41

def validate!
  raise ArgumentError, 'n must be positive' unless n.is_a?(Numeric) && n.positive?
  raise ArgumentError, "action must be 'buy' or 'sell'" unless ACTION_TYPES.include?(action)
end