Module: Rladr::New
- Defined in:
- lib/rladr/new.rb
Class Method Summary collapse
- .execute(title) ⇒ Object
- .next_id(path) ⇒ Object
- .note_content(id, title) ⇒ Object
- .note_filename(id, path, title) ⇒ Object
Class Method Details
.execute(title) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# 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) ⇒ Object
16 17 18 19 20 21 22 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rladr/new.rb', line 28 def note_content(id, title) " # \#{id}. \#{title}\n\n Date: \#{Date.today.to_s}\n\n ## Status\n\n Accepted\n\n ## Context\n\n TODO\n\n ## Decision\n\n TODO\n\n ## Consequences\n\n TODO\n STR\nend\n" |
.note_filename(id, path, title) ⇒ Object
24 25 26 |
# File 'lib/rladr/new.rb', line 24 def note_filename(id, path, title) "#{path}/#{"%05d" % id}-#{title.downcase.gsub(' ', '-')}.md" end |