Class: Ronin::Web::Spider::Archive
- Inherits:
-
Object
- Object
- Ronin::Web::Spider::Archive
- Defined in:
- lib/ronin/web/spider/archive.rb
Overview
Represents a web archive directory.
Example
Spider a host and archive every web page:
require 'ronin/web/spider'
require 'ronin/web/spider/archive'
Ronin::Web::Spider::Archive.open('path/to/root') do |archive|
Ronin::Web::Spider.every_page(host: 'example.com') do |page|
archive.write(page.url,page.body)
end
end
Direct Known Subclasses
Instance Attribute Summary collapse
-
#root ⇒ String
readonly
The path to the archive root directory.
Class Method Summary collapse
-
.open(root) {|archive| ... } ⇒ GitArchive
Creates the archive and the archive's directory, if it already does not exist.
Instance Method Summary collapse
-
#initialize(root) ⇒ Archive
constructor
Initializes the archive.
-
#to_s ⇒ String
Converts the archive to a String.
-
#write(url, body) ⇒ String
Archives a webpage.
Constructor Details
Instance Attribute Details
#root ⇒ String (readonly)
The path to the archive root directory.
47 48 49 |
# File 'lib/ronin/web/spider/archive.rb', line 47 def root @root end |
Class Method Details
.open(root) {|archive| ... } ⇒ GitArchive
Creates the archive and the archive's directory, if it already does not exist.
75 76 77 78 79 80 81 82 |
# File 'lib/ronin/web/spider/archive.rb', line 75 def self.open(root) archive = new(root) FileUtils.mkdir_p(archive.root) yield archive if block_given? return archive end |
Instance Method Details
#to_s ⇒ String
Converts the archive to a String.
113 114 115 |
# File 'lib/ronin/web/spider/archive.rb', line 113 def to_s @root end |
#write(url, body) ⇒ String
Archives a webpage.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ronin/web/spider/archive.rb', line 96 def write(url,body) absolute_path = File.join(@root,url.request_uri[1..]) absolute_path << 'index.html' if absolute_path.end_with?('/') parent_dir = File.dirname(absolute_path) FileUtils.mkdir_p(parent_dir) unless File.directory?(parent_dir) File.write(absolute_path,body) return absolute_path end |