Class: Finviz::QuotesFetcher
- Inherits:
-
Object
- Object
- Finviz::QuotesFetcher
- Defined in:
- lib/finviz/quotes_fetcher.rb
Overview
Fetch the details of the security
Instance Attribute Summary collapse
-
#tickers ⇒ Object
readonly
Returns the value of attribute tickers.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tickers: []) ⇒ QuotesFetcher
constructor
A new instance of QuotesFetcher.
Constructor Details
#initialize(tickers: []) ⇒ QuotesFetcher
Returns a new instance of QuotesFetcher.
14 15 16 |
# File 'lib/finviz/quotes_fetcher.rb', line 14 def initialize(tickers: []) @tickers = Array(tickers) end |
Instance Attribute Details
#tickers ⇒ Object (readonly)
Returns the value of attribute tickers.
18 19 20 |
# File 'lib/finviz/quotes_fetcher.rb', line 18 def tickers @tickers end |
Class Method Details
.dangerous_methods ⇒ Object
7 8 9 10 11 12 |
# File 'lib/finviz/quotes_fetcher.rb', line 7 def self.dangerous_methods @dangerous_methods ||= OpenStruct.instance_methods .map(&:to_s) .select {|m| m.length <=5 } .reject {|m| m =~ /!|\?|\>|\<|\=|_|\[|\]/ } end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/finviz/quotes_fetcher.rb', line 20 def call Quotes.new.tap do |result| all_pages.each do |page| page.html.css("#ticker").zip(page.html.css(".snapshot-table2")).each do |(ticker_xpath, table_xpath)| result.add_quote_from_xpath(ticker_xpath, table_xpath) end end self.class.dangerous_methods.each { |m| result.instance_eval("undef :#{m}") } end end |