Class: StockcliApp::Stock

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Stock

The instances of stocks should be initialized with an array that includes information that was scraped using the scraper class The initialized stock should contain information about the Sr no, name, symbol, url and marketcap



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

def initialize(array)
  stock_array = array
  @srno = stock_array[0]
  @symbol = stock_array[1]
  @name = stock_array[2]
  @url = stock_array[3]
  @price = stock_array[4]
  @mktcap = stock_array[5]
  @sector = stock_array[6]
  @change = stock_array[7]
  @@all << self
end

Instance Attribute Details

#changeObject

Returns the value of attribute change.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def change
  @change
end

#epsObject

Returns the value of attribute eps.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def eps
  @eps
end

#indexObject

Returns the value of attribute index.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def index
  @index
end

#mktcapObject

Returns the value of attribute mktcap.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def mktcap
  @mktcap
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def name
  @name
end

#peratioObject

Returns the value of attribute peratio.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def peratio
  @peratio
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def price
  @price
end

#sectorObject

Returns the value of attribute sector.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def sector
  @sector
end

#srnoObject

Returns the value of attribute srno.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def srno
  @srno
end

#symbolObject

Returns the value of attribute symbol.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def symbol
  @symbol
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/stockcli_app/stock.rb', line 3

def url
  @url
end

Class Method Details

.allObject



31
32
33
# File 'lib/stockcli_app/stock.rb', line 31

def self.all
  @@all
end

.create_from_scraper_array(outer_array) ⇒ Object



24
25
26
27
28
# File 'lib/stockcli_app/stock.rb', line 24

def self.create_from_scraper_array(outer_array)
  outer_array.each do |inner_array|
    stock = StockcliApp::Stock.new(inner_array)
  end
end

Instance Method Details

#add_stock_info(info) ⇒ Object



35
36
37
38
39
40
# File 'lib/stockcli_app/stock.rb', line 35

def add_stock_info(info)
  array = info
  @index = array[0]
  @peratio = array[1]
  @eps = array[2]
end