class Snapshotify::Writer
Attributes
emitter[RW]
resource[RW]
Public Class Methods
new(resource)
click to toggle source
# File lib/snapshotify/writer.rb, line 5 def initialize resource self.resource = resource end
Public Instance Methods
canonical_filename()
click to toggle source
# File lib/snapshotify/writer.rb, line 13 def canonical_filename if host == parent_host "#{filename}" else "/#{host}#{filename}" end end
write()
click to toggle source
# File lib/snapshotify/writer.rb, line 9 def write write_file end
Private Instance Methods
ensure_directory(filename)
click to toggle source
# File lib/snapshotify/writer.rb, line 57 def ensure_directory filename dir = File.dirname(filename) unless File.directory?(dir) FileUtils.mkdir_p(dir) end end
filename()
click to toggle source
# File lib/snapshotify/writer.rb, line 45 def filename @filename ||= begin path = resource.url.uri.path if path.end_with?('/') return path + 'index.html' elsif !path.split('/').last.include?(".") return path + '/index.html' end path end end
full_filename()
click to toggle source
# File lib/snapshotify/writer.rb, line 35 def full_filename @full_filename ||= begin if host == parent_host || !parent_host "#{host}#{filename}" else "#{parent_host}/#{host}#{filename}" end end end
host()
click to toggle source
# File lib/snapshotify/writer.rb, line 64 def host resource.url.host end
parent_host()
click to toggle source
# File lib/snapshotify/writer.rb, line 68 def parent_host resource.url.parent_host end
write_file()
click to toggle source
# File lib/snapshotify/writer.rb, line 24 def write_file return if File.exist?(full_filename) ensure_directory full_filename emitter.log("! Saving #{full_filename}") File.open(full_filename, 'w') do |file| file.write(resource.data) end end