Class: Finviz::Crawler
- Inherits:
-
Object
- Object
- Finviz::Crawler
- Defined in:
- lib/finviz/crawler.rb
Overview
Async way to fetch the data
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(paths: []) ⇒ Crawler
constructor
A new instance of Crawler.
- #result ⇒ Object
Constructor Details
#initialize(paths: []) ⇒ Crawler
Returns a new instance of Crawler.
17 18 19 |
# File 'lib/finviz/crawler.rb', line 17 def initialize(paths: []) @paths = Array(paths) end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
21 22 23 |
# File 'lib/finviz/crawler.rb', line 21 def paths @paths end |
Class Method Details
.call(*args) ⇒ Object
12 13 14 |
# File 'lib/finviz/crawler.rb', line 12 def call(*args) new(*args).tap(&:fetch).result end |
Instance Method Details
#fetch ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/finviz/crawler.rb', line 23 def fetch async do paths.each do |path| response = internet.get(path.to_s, headers) result << OpenStruct.new(path: path, html: Nokogiri::HTML(response.read)) end end end |
#result ⇒ Object
32 33 34 |
# File 'lib/finviz/crawler.rb', line 32 def result @result ||= [] end |