Class: OptionLab::Models::Stock
- Defined in:
- lib/option_lab/models.rb
Overview
Stock position model
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#n ⇒ Object
Returns the value of attribute n.
-
#prev_pos ⇒ Object
Returns the value of attribute prev_pos.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Stock
constructor
A new instance of Stock.
- #validate! ⇒ Object
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
#action ⇒ Object
Returns the value of attribute action.
33 34 35 |
# File 'lib/option_lab/models.rb', line 33 def action @action end |
#n ⇒ Object
Returns the value of attribute n.
33 34 35 |
# File 'lib/option_lab/models.rb', line 33 def n @n end |
#prev_pos ⇒ Object
Returns the value of attribute prev_pos.
33 34 35 |
# File 'lib/option_lab/models.rb', line 33 def prev_pos @prev_pos end |
#type ⇒ Object (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
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 |