module Rladr::New
Public Class Methods
execute(title)
click to toggle source
# File lib/rladr/new.rb, line 6 def execute(title) path = File.read('.rladr') id = next_id(path) filename = note_filename(id, path, title) File.write(filename, note_content(id, title)) puts ":: Created #{filename}" end
next_id(path)
click to toggle source
# File lib/rladr/new.rb, line 16 def next_id(path) ids = Dir["./#{path}/*.md"].map do |filename| filename.split('/')[-1].split('-')[0].to_i end (ids + [0]).max + 1 end
note_content(id, title)
click to toggle source
# File lib/rladr/new.rb, line 28 def note_content(id, title) <<~STR # #{id}. #{title} Date: #{Date.today.to_s} ## Status Accepted ## Context TODO ## Decision TODO ## Consequences TODO STR end
note_filename(id, path, title)
click to toggle source
# File lib/rladr/new.rb, line 24 def note_filename(id, path, title) "#{path}/#{"%05d" % id}-#{title.downcase.gsub(' ', '-')}.md" end