Class: Ncn::Note
- Inherits:
-
Object
- Object
- Ncn::Note
- Defined in:
- lib/ncn/note.rb
Constant Summary collapse
- MAX_TITLE_LENGTH =
80- OMISSION =
"..."
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(id:, created: nil, tags: nil, body: "") ⇒ Note
constructor
A new instance of Note.
- #meta ⇒ Object
- #path ⇒ Object
- #title ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #uniq_tags ⇒ Object
Constructor Details
#initialize(id:, created: nil, tags: nil, body: "") ⇒ Note
Returns a new instance of Note.
9 10 11 12 13 14 |
# File 'lib/ncn/note.rb', line 9 def initialize(id:, created: nil, tags: nil, body: "") @id = id @created = created || Time.now @tags = @body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/ncn/note.rb', line 7 def body @body end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
6 7 8 |
# File 'lib/ncn/note.rb', line 6 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/ncn/note.rb', line 6 def id @id end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/ncn/note.rb', line 7 def @tags end |
Instance Method Details
#meta ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ncn/note.rb', line 22 def { "title" => title, "tags" => csv(), "created" => created.to_s } end |
#path ⇒ Object
35 36 37 |
# File 'lib/ncn/note.rb', line 35 def path NotePathBuilder.new(id: id, created: created).path end |
#title ⇒ Object
16 17 18 19 20 |
# File 'lib/ncn/note.rb', line 16 def title first_line = body.to_s.strip.lines.first.to_s.strip.gsub(/^#+\s+/, "") return first_line if first_line.length < MAX_TITLE_LENGTH first_line[0..(MAX_TITLE_LENGTH - OMISSION.length.succ)] + OMISSION end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/ncn/note.rb', line 39 def to_h { id: id, created: created, tags: , body: body } end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/ncn/note.rb', line 48 def to_s "#{.to_yaml}---\n\n#{body.strip}" end |
#uniq_tags ⇒ Object
30 31 32 33 |
# File 'lib/ncn/note.rb', line 30 def return [] unless .uniq(&:downcase) end |