Class: Vita::Garden

Inherits:
Object
  • Object
show all
Defined in:
lib/vita/garden.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, notes) ⇒ Garden

Returns a new instance of Garden.



25
26
27
28
29
# File 'lib/vita/garden.rb', line 25

def initialize(root, notes)
  @root = File.expand_path(root)
  @title = File.basename(root)
  self.notes = notes
end

Instance Attribute Details

#notesObject

Returns the value of attribute notes.



7
8
9
# File 'lib/vita/garden.rb', line 7

def notes
  @notes
end

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/vita/garden.rb', line 7

def root
  @root
end

#titleObject (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

.note_filename_pattern(root) ⇒ Object



21
22
23
# File 'lib/vita/garden.rb', line 21

def self.note_filename_pattern(root)
  File.join(root, "*.*")
end

.read(root) ⇒ Object



9
10
11
# File 'lib/vita/garden.rb', line 9

def self.read(root)
  new(root, Garden.get_notes(root))
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

Returns:

  • (Boolean)


35
36
37
# File 'lib/vita/garden.rb', line 35

def empty?
  @notes.empty?
end

#home_noteObject



51
52
53
# File 'lib/vita/garden.rb', line 51

def home_note
  self["home"]
end

#linkable_notesObject



47
48
49
# File 'lib/vita/garden.rb', line 47

def linkable_notes
  @notes - [home_note]
end


55
56
57
# File 'lib/vita/garden.rb', line 55

def links
  notes.flat_map(&:outlinks)
end


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_patternObject



63
64
65
# File 'lib/vita/garden.rb', line 63

def note_filename_pattern
  self.class.note_filename_pattern(root)
end

#update!Object



31
32
33
# File 'lib/vita/garden.rb', line 31

def update!
  self.notes = Garden.get_notes(root)
end