Class: MyTradeWizard::WatchList

Inherits:
Object
  • Object
show all
Defined in:
lib/mytradewizard/watch_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stocks = []) ⇒ WatchList

Returns a new instance of WatchList.



6
7
8
9
# File 'lib/mytradewizard/watch_list.rb', line 6

def initialize(stocks = [])
  @stocks = []
  self << stocks
end

Instance Attribute Details

#stocksObject

Returns the value of attribute stocks.



4
5
6
# File 'lib/mytradewizard/watch_list.rb', line 4

def stocks
  @stocks
end

Instance Method Details

#<<(x) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mytradewizard/watch_list.rb', line 11

def <<(x)
  if x.is_a?(MyTradeWizard::Stock)
    @stocks << x
  elsif x.is_a?(Array) && x.first.is_a?(MyTradeWizard::Stock)
    x.each { |stock| @stocks << stock }
  elsif x.is_a?(String)
    @stocks << MyTradeWizard::Stock.new(x)
  elsif x.is_a?(Array) && x.first.is_a?(String)
    x.each { |symbol| @stocks << MyTradeWizard::Stock.new(symbol) }
  end
end

#each(&block) ⇒ Object



23
24
25
# File 'lib/mytradewizard/watch_list.rb', line 23

def each(&block)
  @stocks.each(&block)
end

#remove(positions) ⇒ Object



27
28
29
# File 'lib/mytradewizard/watch_list.rb', line 27

def remove(positions)
  @stocks.reject { |stock| positions.any? { |position| position.stock == stock } }
end