class DayOne2MD::MarkdownEntry

Attributes

content[RW]
date[RW]
title[RW]

Public Instance Methods

dir() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 23
def dir
  @dir || Dir.pwd
end
dir=(dir) click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 19
def dir=(dir)
  @dir = dir if dir
end
filename() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 9
def filename
  s = [ formated_date ]
  s << formated_title if formated_title
  s.join(' ') + '.md'
end
save() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 15
def save
  valid? ? (write_file; true) : false
end

Private Instance Methods

formated_date() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 37
def formated_date
  date.strftime('%Y-%m-%d')
end
formated_title() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 41
def formated_title
  title.gsub('/', '-') if title
end
path() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 33
def path
  File.join(dir, filename)
end
write_file() click to toggle source
# File lib/dayone2md/markdown_entry.rb, line 29
def write_file
  File.open(path, 'w') { |file| file << content }
end