Class: Alphavcli::Search
- Inherits:
-
Object
- Object
- Alphavcli::Search
- Defined in:
- lib/alphavcli/search.rb
Constant Summary collapse
- @@histroy =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#query ⇒ Object
Returns the value of attribute query.
-
#results ⇒ Object
Returns the value of attribute results.
-
#ticker ⇒ Object
Returns the value of attribute ticker.
Class Method Summary collapse
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(query) ⇒ Search
constructor
A new instance of Search.
- #spacetimes(n) ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/alphavcli/search.rb', line 6 def name @name end |
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/alphavcli/search.rb', line 6 def query @query end |
#results ⇒ Object
Returns the value of attribute results.
6 7 8 |
# File 'lib/alphavcli/search.rb', line 6 def results @results end |
#ticker ⇒ Object
Returns the value of attribute ticker.
6 7 8 |
# File 'lib/alphavcli/search.rb', line 6 def ticker @ticker end |
Class Method Details
.history ⇒ Object
25 26 27 |
# File 'lib/alphavcli/search.rb', line 25 def self.history @@histroy end |
Instance Method Details
#display ⇒ Object
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 |