Class: PageDownloader
- Inherits:
-
Object
- Object
- PageDownloader
- Defined in:
- lib/page_downloader.rb,
lib/page_downloader/filters.rb,
lib/page_downloader/version.rb,
lib/page_downloader/filters/embed_style.rb,
lib/page_downloader/filters/embed_script.rb,
lib/page_downloader/remote_content_fetcher.rb,
lib/page_downloader/filters/to_document_object.rb,
lib/page_downloader/filters/document_object_to_string.rb
Defined Under Namespace
Classes: Filters, RemoteContentFetcher
Constant Summary collapse
- VERSION =
"1.0"
Instance Attribute Summary collapse
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page, options = {}) ⇒ PageDownloader
constructor
A new instance of PageDownloader.
- #to_file(destination) ⇒ Object
Constructor Details
#initialize(page, options = {}) ⇒ PageDownloader
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/page_downloader.rb', line 13 def initialize(page, = {}) @page = page @fetcher = .fetch(:fetcher, RemoteContentFetcher.new) @filters = [:filters] unless @filters resolver = UrlResolver.new(referer: page) = { fetcher: fetcher, url_resolver: resolver } @filters ||= Filters.new [ Filters::ToDocumentObject.new, Filters::EmbedScript.new(), Filters::EmbedStyle.new(), Filters::DocumentObjectToString.new, ] end end |
Instance Attribute Details
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
11 12 13 |
# File 'lib/page_downloader.rb', line 11 def fetcher @fetcher end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
11 12 13 |
# File 'lib/page_downloader.rb', line 11 def filters @filters end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
11 12 13 |
# File 'lib/page_downloader.rb', line 11 def page @page end |
Instance Method Details
#to_file(destination) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/page_downloader.rb', line 31 def to_file(destination) content = filters.filter(fetcher.fetch(page)) File.open(destination, "w") do |f| f.puts(content) end end |