Class: JamrockStocks::Stock

Inherits:
Object
  • Object
show all
Defined in:
lib/jamrock_stocks/stock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changeObject (readonly)

Returns the value of attribute change.



4
5
6
# File 'lib/jamrock_stocks/stock.rb', line 4

def change
  @change
end

#previous_priceObject (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

#priceObject (readonly)

Returns the value of attribute price.



4
5
6
# File 'lib/jamrock_stocks/stock.rb', line 4

def price
  @price
end

#symbolObject (readonly)

Returns the value of attribute symbol.



4
5
6
# File 'lib/jamrock_stocks/stock.rb', line 4

def symbol
  @symbol
end

#updated_atObject (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

#volumeObject (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_changeObject



15
16
17
# File 'lib/jamrock_stocks/stock.rb', line 15

def percentage_change
  (@change / @previous_price) * 100
end