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.



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

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



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

def content
  IO.readlines(path)
end

#date_modifiedObject



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

def date_modified
  @date_modified ||= mtime.to_date
end

#mtimeObject



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

def mtime
  File.mtime(path)
end

#pretty_printed_mtimeObject



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

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



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

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

#titleObject



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

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