Class: Quiver::Notebook
- Inherits:
-
Object
- Object
- Quiver::Notebook
- Defined in:
- lib/quiver/notebook.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #add(note) ⇒ Object
- #each(include_content: false) ⇒ Object
-
#initialize(meta:, path: nil, root: nil) ⇒ Notebook
constructor
A new instance of Notebook.
- #name ⇒ Object
- #save ⇒ Object
Constructor Details
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
3 4 5 |
# File 'lib/quiver/notebook.rb', line 3 def @meta end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/quiver/notebook.rb', line 3 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/quiver/notebook.rb', line 3 def root @root end |
Instance Method Details
#add(note) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/quiver/notebook.rb', line 26 def add(note) raise 'this note already added' if note.path note.['uuid'] ||= SecureRandom.uuid.upcase note.path = @path + "#{note.['uuid']}.qvnote" note.adapter = @adapter note.save end |
#each(include_content: false) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/quiver/notebook.rb', line 13 def each(include_content: false) raise 'This notebook has no root' unless @adapter @adapter.each(@path, 'qvnote') do |path| content = JSON.parse(@adapter.load(@path + path + 'content.json')) if include_content = JSON.parse(@adapter.load(@path + path + 'meta.json')) yield Note.new(content: content, meta: , path: @path + path, notebook: self) end end |
#name ⇒ Object
10 11 12 |
# File 'lib/quiver/notebook.rb', line 10 def name @meta['name'] end |
#save ⇒ Object
21 22 23 24 25 |
# File 'lib/quiver/notebook.rb', line 21 def save raise 'add to root first!' unless @path && @adapter adapter.mkpath(@path) adapter.save(@path + 'meta.json', @meta.to_json) end |