Class: Web2Text::FilePrinter
- Inherits:
-
Object
- Object
- Web2Text::FilePrinter
- Defined in:
- lib/web2text/formatters.rb
Overview
Writes one file per page
Instance Method Summary collapse
- #append(doc, uri) ⇒ Object
- #close ⇒ Object
-
#initialize(crawl, out_dir) ⇒ FilePrinter
constructor
A new instance of FilePrinter.
Constructor Details
#initialize(crawl, out_dir) ⇒ FilePrinter
Returns a new instance of FilePrinter.
26 27 28 29 30 31 32 33 |
# File 'lib/web2text/formatters.rb', line 26 def initialize(crawl, out_dir) root_path = URI(crawl.url).path.to_s root_path = "/" if root_path.empty? @crawl_root = Pathname(root_path) @out_dir = Pathname(out_dir) @out_dir.mkpath end |
Instance Method Details
#append(doc, uri) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/web2text/formatters.rb', line 35 def append(doc, uri) path = @out_dir + Pathname(URI(uri).path).relative_path_from(@crawl_root) if path.extname == "" then path = path + 'index.txt' end path = path.sub_ext('.txt') path.parent.mkpath path.open("w") { |f| f.write(doc) } self end |
#close ⇒ Object
48 49 |
# File 'lib/web2text/formatters.rb', line 48 def close end |