Class: Archive
- Inherits:
-
Object
- Object
- Archive
- Defined in:
- lib/domreactor-redglass/archive.rb
Constant Summary collapse
- REQUIRED_ARCHIVE_FILES =
%w(dom.json metadata.json screenshot.png source.html)
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #browser ⇒ Object
- #dom_elements ⇒ Object
-
#initialize(path, opts = {}) ⇒ Archive
constructor
A new instance of Archive.
- #meta_data ⇒ Object
- #page_source ⇒ Object
- #page_url ⇒ Object
- #screenshot ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Archive
Returns a new instance of Archive.
6 7 8 9 |
# File 'lib/domreactor-redglass/archive.rb', line 6 def initialize(path, opts={}) @path = path @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
2 3 4 |
# File 'lib/domreactor-redglass/archive.rb', line 2 def opts @opts end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
2 3 4 |
# File 'lib/domreactor-redglass/archive.rb', line 2 def path @path end |
Class Method Details
.is_valid_page_archive?(file) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/domreactor-redglass/archive.rb', line 35 def self.is_valid_page_archive?(file) is_valid = false if File.directory? file dir_files = Dir.entries(file).delete_if {|name| name == '.' || name == '..'} is_valid = dir_files.sort == REQUIRED_ARCHIVE_FILES.sort end is_valid end |
Instance Method Details
#browser ⇒ Object
15 16 17 |
# File 'lib/domreactor-redglass/archive.rb', line 15 def browser [:browser] end |
#dom_elements ⇒ Object
23 24 25 |
# File 'lib/domreactor-redglass/archive.rb', line 23 def dom_elements @dom_elements ||= File.open("#{path}/dom.json", 'rb') {|f| f.read} end |
#meta_data ⇒ Object
11 12 13 |
# File 'lib/domreactor-redglass/archive.rb', line 11 def @meta_data = parse_json_file("#{path}/metadata.json") end |
#page_source ⇒ Object
27 28 29 |
# File 'lib/domreactor-redglass/archive.rb', line 27 def page_source @page_source ||= File.open("#{path}/source.html") {|f| f.read} end |
#page_url ⇒ Object
19 20 21 |
# File 'lib/domreactor-redglass/archive.rb', line 19 def page_url [:page_url] end |
#screenshot ⇒ Object
31 32 33 |
# File 'lib/domreactor-redglass/archive.rb', line 31 def screenshot @file ||= File.open("#{path}/screenshot.png") end |