class Til::NoteList

Attributes

notes[RW]

Public Class Methods

new(notes=Array.new) click to toggle source
# File lib/til/models/note_list.rb, line 7
def initialize(notes=Array.new)
  @notes = notes
end

Public Instance Methods

filter() click to toggle source
# File lib/til/models/note_list.rb, line 23
def filter
  if notes.length == 1
    notes.first
  else
    notes.each_with_index do |note, index|
      puts "#{index+1}) #{note.title.bold} (#{note.subject})"
    end
  
    begin
      choice = ask("Choice: ").to_i
    rescue Interrupt
      warn "\nAborted!"
      abort
    end

    notes.fetch(choice-1) do
      puts "Invalid choice!"
      abort
    end
  end
end
method_missing(m, *args, &block) click to toggle source
# File lib/til/models/note_list.rb, line 45
def method_missing(m, *args, &block)
  notes.send(m, *args, &block)
end
most_recent() click to toggle source
# File lib/til/models/note_list.rb, line 19
def most_recent
  notes.sort { |a, b| b.mtime <=> a.mtime }.fetch(0)
end
sort_by_modified_time() click to toggle source
# File lib/til/models/note_list.rb, line 15
def sort_by_modified_time
  NoteList.new(notes.sort { |a, b| b.mtime <=> a.mtime })
end
to_note_list() click to toggle source
# File lib/til/models/note_list.rb, line 11
def to_note_list
  self
end