module RedditArchiver::FileWriter

Public Instance Methods

ext() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 16
def ext
  ".md"
end
filename() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 12
def filename
  "#{self.year_month_date}_#{self.title_url}"[0..96]
end
filename_with_full_path() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 20
def filename_with_full_path
  File.join(File.dirname(__FILE__), '../../', RedditArchiver.config.directory, subdirectories, filename + ext)
end
subdirectories() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 8
def subdirectories
  self.subreddit ? File.join(subdirectory, self.subreddit) : subdirectory
end
subdirectory() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 4
def subdirectory
  self.class.name.split('::').last.downcase.pluralize
end
target_directory() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 24
def target_directory
  File.dirname(filename_with_full_path)
end
write() click to toggle source
# File lib/reddit_archiver/file_writer.rb, line 28
def write
  Dir.mkdir(target_directory) unless File.directory?(target_directory)
  file = File.new(filename_with_full_path, 'w')
  file.puts(self.file_contents)
  file.close
end