Class: SchwabRb::DataObjects::Mover

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/market_movers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject (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_priceObject (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_shareObject (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_changeObject (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_changeObject (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

#symbolObject (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_volumeObject (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

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

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

Returns:

  • (Boolean)


72
73
74
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 72

def negative_change?
  @net_change&.negative?
end

#net_change_percentageObject



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_volumeObject



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

Returns:

  • (Boolean)


68
69
70
# File 'lib/schwab_rb/data_objects/market_movers.rb', line 68

def positive_change?
  @net_change&.positive?
end

#to_hObject



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_sObject



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