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
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
#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
32 33 34 |
# File 'lib/til/models/note.rb', line 32 def content IO.readlines(path) end |
#date_modified ⇒ Object
36 37 38 |
# File 'lib/til/models/note.rb', line 36 def date_modified @date_modified ||= mtime.to_date end |
#mtime ⇒ Object
8 9 10 |
# File 'lib/til/models/note.rb', line 8 def mtime File.mtime(path) end |
#pretty_printed_mtime ⇒ Object
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 |
#subject ⇒ Object
12 13 14 |
# File 'lib/til/models/note.rb', line 12 def subject /\/([^\/]+)\/[^\/]+$/.match(path)[1] end |
#title ⇒ Object
28 29 30 |
# File 'lib/til/models/note.rb', line 28 def title content[0].gsub("# ","").chomp end |