Class: Hermaeus::Archivist
- Inherits:
-
Object
- Object
- Hermaeus::Archivist
- Defined in:
- lib/hermaeus/archivist.rb
Instance Method Summary collapse
- #add_metadata(apoc) ⇒ Object
-
#initialize ⇒ Archivist
constructor
A new instance of Archivist.
- #prettify(text, length: 80) ⇒ Object
- #save_to_file(apoc) ⇒ Object
Constructor Details
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.} 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 |