Class: Til::Note
- Inherits:
-
Object
- Object
- Til::Note
- Defined in:
- lib/til/models/note.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #content ⇒ Object
- #date_modified ⇒ Object
-
#initialize(path) ⇒ Note
constructor
A new instance of Note.
- #mtime ⇒ Object
- #pretty_printed_mtime ⇒ Object
- #subject ⇒ Object
- #title ⇒ Object
- #to_note_list ⇒ Object
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
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/til/models/note.rb', line 3 def path @path end |
Instance Method Details
#content ⇒ Object
33 34 35 |
# File 'lib/til/models/note.rb', line 33 def content IO.readlines(path) end |
#date_modified ⇒ Object
37 38 39 |
# File 'lib/til/models/note.rb', line 37 def date_modified @date_modified ||= mtime.to_date end |
#mtime ⇒ Object
9 10 11 |
# File 'lib/til/models/note.rb', line 9 def mtime File.mtime(path) end |
#pretty_printed_mtime ⇒ Object
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 |
#subject ⇒ Object
13 14 15 |
# File 'lib/til/models/note.rb', line 13 def subject /\/([^\/]+)\/[^\/]+$/.match(path)[1] end |
#title ⇒ Object
29 30 31 |
# File 'lib/til/models/note.rb', line 29 def title content[0].gsub("# ","").chomp end |
#to_note_list ⇒ Object
41 42 43 |
# File 'lib/til/models/note.rb', line 41 def to_note_list NoteList.new([self]) end |