Class: EasySitemap::Runner
- Inherits:
-
Object
- Object
- EasySitemap::Runner
- Defined in:
- lib/easy_sitemap/runner.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(urls, api_key: nil) ⇒ Runner
constructor
A new instance of Runner.
- #perform ⇒ Object
Constructor Details
#initialize(urls, api_key: nil) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 |
# File 'lib/easy_sitemap/runner.rb', line 6 def initialize(urls, api_key: nil) @urls = urls @api_key = api_key @result = {} end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/easy_sitemap/runner.rb', line 4 def result @result end |
Class Method Details
.perform(filename: 'sitemap.xml', thread_count: 5, api_key: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/easy_sitemap/runner.rb', line 12 def self.perform(filename: 'sitemap.xml', thread_count: 5, api_key: nil) doc = File.open(filename) { |f| Nokogiri::XML(f) } runners = doc.xpath("//loc"). map(&:text). in_groups(thread_count, false). map { |group| Runner.new(group, api_key: api_key) } threads = runners.map { |runner| Thread.new { runner.perform } } threads.each { |thr| thr.join } runners.map(&:result).inject(:merge) end |
Instance Method Details
#perform ⇒ Object
26 27 28 29 30 |
# File 'lib/easy_sitemap/runner.rb', line 26 def perform @urls.each do |url| ping_url(url) end end |