Class: Staticfy::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/staticfy/crawler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Crawler

Returns a new instance of Crawler.



25
26
27
28
# File 'lib/staticfy/crawler.rb', line 25

def initialize(url, options = {})
  @url = url
  @options = options
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



23
24
25
# File 'lib/staticfy/crawler.rb', line 23

def url
  @url
end

Instance Method Details

#crawlObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/staticfy/crawler.rb', line 30

def crawl
  Anemone.crawl(url) do |anemone|
    anemone.on_every_page do |page|
      local_path = File.join(@options[:output], page.local_uri)

      File.open(local_path, "wb") do |file|
        file << page.local_body
      end

      puts "Saved #{local_path}"
    end
  end
end