class DailyLog::Entry

One Daily Log journal Entry

Constants

TEMPLATE_PATH

Default path for the daily entry Markdown template

Attributes

day[R]

The Day this Entry is for

pathname[R]

The Pathname of the file to the Entry

Public Class Methods

new(day) click to toggle source

Create a new Entry

day - The Day we're creating a new Entry for

# File lib/daily_log/entry.rb, line 28
def initialize(day)
  @day = day
  @pathname = Pathname.new(day.date)
end

Public Instance Methods

open() click to toggle source

Open the Entry file in the text editor. If one doens't already exist, create it for this Day

# File lib/daily_log/entry.rb, line 45
def open
  ensure!
  open_in_editor
end
print() click to toggle source

Print the contents of this Entry to STDOUT. If no entry exists, print a warning.

Private Instance Methods

ensure!() click to toggle source
# File lib/daily_log/entry.rb, line 80
def ensure!
  return if exists?
  FileUtils.mkdir_p(pathname.dirname)
  template = ERB.new File.read(template_path)
  File.open(pathname.to_s, "wb") do |file|
    file.write template.result(binding)
  end
end
exists?() click to toggle source
# File lib/daily_log/entry.rb, line 76
def exists?
  File.exist?(pathname)
end
file() click to toggle source
# File lib/daily_log/entry.rb, line 56
def file
  @file ||= File.open(pathname, 'r')
end
local_template_exists?() click to toggle source
# File lib/daily_log/entry.rb, line 72
def local_template_exists?
  File.exist?(local_template_path)
end
local_template_path() click to toggle source
# File lib/daily_log/entry.rb, line 60
def local_template_path
  "./#{Pathname.dirname}/templates.md.erb"
end
open_in_editor() click to toggle source
# File lib/daily_log/entry.rb, line 52
def open_in_editor
  exec("$EDITOR -w #{pathname}")
end
template_path() click to toggle source
# File lib/daily_log/entry.rb, line 64
def template_path
  if local_template_exists?
    local_template_path
  else
    TEMPLATE_PATH
  end
end