Class: Til::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/til/models/note.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Note

Returns a new instance of Note.



5
6
7
# File 'lib/til/models/note.rb', line 5

def initialize path
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/til/models/note.rb', line 3

def path
  @path
end

Instance Method Details

#contentObject



33
34
35
# File 'lib/til/models/note.rb', line 33

def content
  IO.readlines(path)
end

#date_modifiedObject



37
38
39
# File 'lib/til/models/note.rb', line 37

def date_modified
  @date_modified ||= mtime.to_date
end

#mtimeObject



9
10
11
# File 'lib/til/models/note.rb', line 9

def mtime
  File.mtime(path)
end

#pretty_printed_mtimeObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/til/models/note.rb', line 17

def pretty_printed_mtime
  if date_modified == Date.today
    "today"
  elsif date_modified == (Date.today - 1)
    "yesterday"
  elsif date_modified > (Date.today - 6)
    mtime.strftime("%A")
  else 
    mtime.strftime("%b. %-d, %Y")
  end
end

#subjectObject



13
14
15
# File 'lib/til/models/note.rb', line 13

def subject
  /\/([^\/]+)\/[^\/]+$/.match(path)[1]
end

#titleObject



29
30
31
# File 'lib/til/models/note.rb', line 29

def title
  content[0].gsub("# ","").chomp
end

#to_note_listObject



41
42
43
# File 'lib/til/models/note.rb', line 41

def to_note_list
  NoteList.new([self])
end