Class: Archive

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#optsObject (readonly)

Returns the value of attribute opts.



2
3
4
# File 'lib/domreactor-redglass/archive.rb', line 2

def opts
  @opts
end

#pathObject (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

Returns:

  • (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

#browserObject



15
16
17
# File 'lib/domreactor-redglass/archive.rb', line 15

def browser
  [:browser]
end

#dom_elementsObject



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_dataObject



11
12
13
# File 'lib/domreactor-redglass/archive.rb', line 11

def 
  @meta_data = parse_json_file("#{path}/metadata.json")
end

#page_sourceObject



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_urlObject



19
20
21
# File 'lib/domreactor-redglass/archive.rb', line 19

def page_url
  [:page_url]
end

#screenshotObject



31
32
33
# File 'lib/domreactor-redglass/archive.rb', line 31

def screenshot
  @file ||= File.open("#{path}/screenshot.png")
end