Class: Vita::GardenNote
- Inherits:
-
Object
- Object
- Vita::GardenNote
- Defined in:
- lib/vita/garden_note.rb
Constant Summary collapse
- EXCERPT_LENGTH =
160
Instance Attribute Summary collapse
-
#garden ⇒ Object
readonly
Returns the value of attribute garden.
Instance Method Summary collapse
-
#all_names ⇒ Object
Get all names for this note, including its title and synonyms.
- #backlinks ⇒ Object
- #content ⇒ Object
- #excerpt ⇒ Object
- #home? ⇒ Boolean
- #html ⇒ Object
-
#initialize(garden, note) ⇒ GardenNote
constructor
A new instance of GardenNote.
- #links ⇒ Object
-
#names_regexp ⇒ Object
Get a regular expression that matches any of this note’s names surrounded by word boundaries.
- #outlinks ⇒ Object
- #path ⇒ Object
-
#synonyms ⇒ Object
Get alternative names for this note.
-
#title ⇒ Object
Get this note’s primary title.
Constructor Details
#initialize(garden, note) ⇒ GardenNote
Returns a new instance of GardenNote.
10 11 12 13 |
# File 'lib/vita/garden_note.rb', line 10 def initialize(garden, note) @garden = garden @note = note end |
Instance Attribute Details
#garden ⇒ Object (readonly)
Returns the value of attribute garden.
8 9 10 |
# File 'lib/vita/garden_note.rb', line 8 def garden @garden end |
Instance Method Details
#all_names ⇒ Object
Get all names for this note, including its title and synonyms.
30 31 32 |
# File 'lib/vita/garden_note.rb', line 30 def all_names [title, *synonyms] end |
#backlinks ⇒ Object
71 72 73 |
# File 'lib/vita/garden_note.rb', line 71 def backlinks garden.links_to(self) end |
#content ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/vita/garden_note.rb', line 49 def content if @note.content.start_with? "Synonyms:" @note.content[@note.content.index("\n") + 1..] else @note.content end end |
#excerpt ⇒ Object
61 62 63 64 65 |
# File 'lib/vita/garden_note.rb', line 61 def excerpt excerpt = content[0, EXCERPT_LENGTH] excerpt += "…" if excerpt.length < content.length excerpt end |
#home? ⇒ Boolean
79 80 81 |
# File 'lib/vita/garden_note.rb', line 79 def home? garden.home_note == self end |
#html ⇒ Object
57 58 59 |
# File 'lib/vita/garden_note.rb', line 57 def html Format.for_filename(@note.filename).to_html(content) end |
#links ⇒ Object
75 76 77 |
# File 'lib/vita/garden_note.rb', line 75 def links outlinks + backlinks end |
#names_regexp ⇒ Object
Get a regular expression that matches any of this note’s names surrounded by word boundaries.
36 37 38 39 |
# File 'lib/vita/garden_note.rb', line 36 def names_regexp elements = all_names.map { |name| /#{Regexp.quote(name)}/i } /\b#{Regexp.union(elements)}\b/ end |
#outlinks ⇒ Object
67 68 69 |
# File 'lib/vita/garden_note.rb', line 67 def outlinks @outlinks ||= create_outlinks end |
#path ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/vita/garden_note.rb', line 41 def path if home? "index.html" else @note.title.downcase.gsub(/\s+/, "-") + ".html" end end |
#synonyms ⇒ Object
Get alternative names for this note.
21 22 23 24 25 26 27 |
# File 'lib/vita/garden_note.rb', line 21 def synonyms if @note.content.start_with? "Synonyms:" @note.content[9..@note.content.index("\n")].split(",").map(&:strip) else [] end end |
#title ⇒ Object
Get this note’s primary title.
16 17 18 |
# File 'lib/vita/garden_note.rb', line 16 def title @note.title end |