Class: Result

Inherits:
Object
  • Object
show all
Defined in:
lib/alphavcli/result.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticker, name = nil) ⇒ Result



4
5
6
7
8
# File 'lib/alphavcli/result.rb', line 4

def initialize(ticker,name=nil)
    @ticker=ticker
    @name=name
    @@all.push(self)
end

Instance Attribute Details

#dailyObject

Returns the value of attribute daily.



2
3
4
# File 'lib/alphavcli/result.rb', line 2

def daily
  @daily
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/alphavcli/result.rb', line 2

def name
  @name
end

#tickerObject

Returns the value of attribute ticker.



2
3
4
# File 'lib/alphavcli/result.rb', line 2

def ticker
  @ticker
end

Class Method Details

.allObject



29
30
31
# File 'lib/alphavcli/result.rb', line 29

def self.all
    @@all
end

.new_from_ticker(ticker) ⇒ Object



10
11
12
13
# File 'lib/alphavcli/result.rb', line 10

def self.new_from_ticker(ticker)
    new_result = self.new(ticker)
    self.new(ticker) 
end

Instance Method Details

#getTimeSeriesObject



15
16
17
18
19
20
21
22
23
# File 'lib/alphavcli/result.rb', line 15

def getTimeSeries
    data = open("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=#{@ticker}&apikey=#{Alphavcli::Cli.returnKey}").read
    data = JSON.parse(data)
    
    #data = data["Time Series (Daily)"]
    @daily = data = data["Time Series (Daily)"].map{|k,v|
        {:day=>k, :price=>v["4. close"].to_f}
    }
end

#weekObject



25
26
27
# File 'lib/alphavcli/result.rb', line 25

def week
    getTimeSeries
end