Class: SchwabRb::DataObjects::Mover
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::Mover
- Defined in:
- lib/schwab_rb/data_objects/market_movers.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#last_price ⇒ Object
readonly
Returns the value of attribute last_price.
-
#market_share ⇒ Object
readonly
Returns the value of attribute market_share.
-
#net_change ⇒ Object
readonly
Returns the value of attribute net_change.
-
#net_percent_change ⇒ Object
readonly
Returns the value of attribute net_percent_change.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#total_volume ⇒ Object
readonly
Returns the value of attribute total_volume.
-
#trades ⇒ Object
readonly
Returns the value of attribute trades.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
-
#initialize(data) ⇒ Mover
constructor
A new instance of Mover.
- #negative_change? ⇒ Boolean
- #net_change_percentage ⇒ Object
- #percentage_of_total_volume ⇒ Object
- #positive_change? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Mover
Returns a new instance of Mover.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 50 def initialize(data) @description = data[:description] @volume = data[:volume] @last_price = data[:lastPrice] @net_change = data[:netChange] @market_share = data[:marketShare] @total_volume = data[:totalVolume] @trades = data[:trades] @net_percent_change = data[:netPercentChange] @symbol = data[:symbol] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def description @description end |
#last_price ⇒ Object (readonly)
Returns the value of attribute last_price.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def last_price @last_price end |
#market_share ⇒ Object (readonly)
Returns the value of attribute market_share.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def market_share @market_share end |
#net_change ⇒ Object (readonly)
Returns the value of attribute net_change.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def net_change @net_change end |
#net_percent_change ⇒ Object (readonly)
Returns the value of attribute net_percent_change.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def net_percent_change @net_percent_change end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def symbol @symbol end |
#total_volume ⇒ Object (readonly)
Returns the value of attribute total_volume.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def total_volume @total_volume end |
#trades ⇒ Object (readonly)
Returns the value of attribute trades.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def trades @trades end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
47 48 49 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 47 def volume @volume end |
Instance Method Details
#negative_change? ⇒ Boolean
72 73 74 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 72 def negative_change? @net_change&.negative? end |
#net_change_percentage ⇒ Object
76 77 78 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 76 def net_change_percentage (@net_percent_change * 100).round(2) if @net_percent_change end |
#percentage_of_total_volume ⇒ Object
62 63 64 65 66 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 62 def percentage_of_total_volume return 0.0 if @total_volume.nil? || @total_volume.zero? (@volume / @total_volume.to_f) * 100.0 end |
#positive_change? ⇒ Boolean
68 69 70 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 68 def positive_change? @net_change&.positive? end |
#to_h ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 80 def to_h { symbol: @symbol, description: @description, volume: @volume, last_price: @last_price, net_change: @net_change, market_share: @market_share, total_volume: @total_volume, trades: @trades, net_percent_change: @net_percent_change } end |
#to_s ⇒ Object
94 95 96 |
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 94 def to_s "<Mover symbol: #{@symbol}, volume: #{@volume}, last_price: #{@last_price}, net_change: #{@net_change}>" end |