Class: JamrockStocks::Stock
- Inherits:
-
Object
- Object
- JamrockStocks::Stock
- Defined in:
- lib/jamrock_stocks/stock.rb
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
-
#previous_price ⇒ Object
readonly
Returns the value of attribute previous_price.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
-
#initialize(symbol:, price:, change: 0.0, volume: 0, updated_at:) ⇒ Stock
constructor
A new instance of Stock.
- #percentage_change ⇒ Object
Constructor Details
#initialize(symbol:, price:, change: 0.0, volume: 0, updated_at:) ⇒ Stock
Returns a new instance of Stock.
6 7 8 9 10 11 12 13 |
# File 'lib/jamrock_stocks/stock.rb', line 6 def initialize(symbol:, price:, change: 0.0, volume: 0, updated_at:) @symbol = symbol.to_str.upcase @price = price.to_f @change = change.to_f @volume = volume.to_int @previous_price = @price - (@change) @updated_at = updated_at end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def change @change end |
#previous_price ⇒ Object (readonly)
Returns the value of attribute previous_price.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def previous_price @previous_price end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def price @price end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def symbol @symbol end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def updated_at @updated_at end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
4 5 6 |
# File 'lib/jamrock_stocks/stock.rb', line 4 def volume @volume end |
Instance Method Details
#percentage_change ⇒ Object
15 16 17 |
# File 'lib/jamrock_stocks/stock.rb', line 15 def percentage_change (@change / @previous_price) * 100 end |