Class: Hermaeus::Archivist

Inherits:
Object
  • Object
show all
Defined in:
lib/hermaeus/archivist.rb

Instance Method Summary collapse

Constructor Details

#initializeArchivist

Returns a new instance of Archivist.



5
6
7
8
9
# File 'lib/hermaeus/archivist.rb', line 5

def initialize
	@html_filter = HTMLEntities.new
	@config = Config.load[:archive]
	FileUtils.mkdir_p @config[:path]
end

Instance Method Details

#add_metadata(apoc) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hermaeus/archivist.rb', line 11

def  apoc
	str = <<-EOS
---
author: #{apoc.author}
title: #{apoc.title}
date: #{Time.at(apoc.created.to_i).iso8601}
reddit: #{apoc.id}
---

	EOS
end

#prettify(text, length: 80) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/hermaeus/archivist.rb', line 35

def prettify text, length: 80
	@html_filter.decode(text)
	.split("\n").map do |line|
		# Put the newline back in
		line << "\n"
		break_line line
	end
	.join
end

#save_to_file(apoc) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hermaeus/archivist.rb', line 23

def save_to_file apoc
	unless apoc.text == "[deleted]" || apoc.text == "[removed]"
		title = @html_filter.decode(title)
		title = apoc.title.downcase.gsub(/[ \/]/, "_").gsub(/[:"',]/, "")
		title << ".html.md"
		File.open(File.join(@config[:path], title), "w+") do |file|
			file << (apoc)
			file << prettify(apoc.text)
		end
	end
end