Class: Vita::Garden
- Inherits:
-
Object
- Object
- Vita::Garden
- Defined in:
- lib/vita/garden.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #[](title) ⇒ Object
- #empty? ⇒ Boolean
- #home_note ⇒ Object
-
#initialize(root, notes) ⇒ Garden
constructor
A new instance of Garden.
- #linkable_notes ⇒ Object
- #links ⇒ Object
- #links_to(note) ⇒ Object
- #note_at_path(path) ⇒ Object
- #note_filename_pattern ⇒ Object
- #update! ⇒ Object
Constructor Details
Instance Attribute Details
#notes ⇒ Object
Returns the value of attribute notes.
7 8 9 |
# File 'lib/vita/garden.rb', line 7 def notes @notes end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/vita/garden.rb', line 7 def root @root end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/vita/garden.rb', line 7 def title @title end |
Class Method Details
.get_notes(root) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/vita/garden.rb', line 13 def self.get_notes(root) unless File.directory? root raise Vita::Error.new("Directory not found at #{root}") end Dir[note_filename_pattern(root)].map { |filename| Note.new(filename) } end |
Instance Method Details
#[](title) ⇒ Object
39 40 41 |
# File 'lib/vita/garden.rb', line 39 def [](title) @notes_hash[title.downcase] end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/vita/garden.rb', line 35 def empty? @notes.empty? end |
#home_note ⇒ Object
51 52 53 |
# File 'lib/vita/garden.rb', line 51 def home_note self["home"] end |
#linkable_notes ⇒ Object
47 48 49 |
# File 'lib/vita/garden.rb', line 47 def linkable_notes @notes - [home_note] end |
#links ⇒ Object
55 56 57 |
# File 'lib/vita/garden.rb', line 55 def links notes.flat_map(&:outlinks) end |
#links_to(note) ⇒ Object
59 60 61 |
# File 'lib/vita/garden.rb', line 59 def links_to(note) links.filter { |link| link.to_note == note } end |
#note_at_path(path) ⇒ Object
43 44 45 |
# File 'lib/vita/garden.rb', line 43 def note_at_path(path) @notes.find { |note| note.path == path } end |
#note_filename_pattern ⇒ Object
63 64 65 |
# File 'lib/vita/garden.rb', line 63 def note_filename_pattern self.class.note_filename_pattern(root) end |