Module: WebpageArchivist::Extracter

Defined in:
lib/webpage-archivist/extracter.rb

Overview

Fetch webpages’ content

Class Method Summary collapse

Class Method Details

.instance_content(id, file) ⇒ Object

Write the full content of a webpage instance into a zip file

id

the instance id

file

the file to write to



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/webpage-archivist/extracter.rb', line 11

def self.instance_content id, file
  @instance = Instance.filter(:id => id).first
  unless @instance
    raise "Instance [#{id}] not found"
  end
  repository = @instance.webpage.repository
  commit = repository.log.find{ |l| l.message == @instance.commit_timestamp }

  unless file.end_with? '.zip'
    file << '.zip'
  end

  if commit
    repository.archive_zip commit.id, file
  else
    raise "Version [#{@instance.commit_timestamp}] not found"
  end
end