Class: Alphavcli::Search

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

Constant Summary collapse

@@histroy =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Search

Returns a new instance of Search.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/alphavcli/search.rb', line 9

def initialize(query)
    data = open("https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=#{query}&apikey=#{Alphavcli::Cli.returnKey}").read
    data = JSON.parse(data)
    
    
    @query=query
    @results = data["bestMatches"].map{|e|
        Result.new(e["1. symbol"],e["2. name"])
        #{:ticker=>e["1. symbol"],:name=>e["2. name"]}
    }
    @@histroy.push(self)
    

    
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/alphavcli/search.rb', line 6

def name
  @name
end

#queryObject

Returns the value of attribute query.



6
7
8
# File 'lib/alphavcli/search.rb', line 6

def query
  @query
end

#resultsObject

Returns the value of attribute results.



6
7
8
# File 'lib/alphavcli/search.rb', line 6

def results
  @results
end

#tickerObject

Returns the value of attribute ticker.



6
7
8
# File 'lib/alphavcli/search.rb', line 6

def ticker
  @ticker
end

Class Method Details

.historyObject



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

def self.history
    @@histroy
end

Instance Method Details

#displayObject



31
32
33
34
35
# File 'lib/alphavcli/search.rb', line 31

def display
    max = @results.map{|result| result["1. symbol"].length}.max
    @results.each{|result|
    puts result["1. symbol"]+(" "*(30-result["1. symbol"].length)) + result["2. name"]}
end

#spacetimes(n) ⇒ Object



37
38
39
# File 'lib/alphavcli/search.rb', line 37

def spacetimes(n)
    out = 3
end