Class: QuiverToolbox::Notebook
- Inherits:
-
Object
- Object
- QuiverToolbox::Notebook
- Defined in:
- lib/quiver_toolbox/notebook.rb
Constant Summary collapse
- EXTENSION =
'qvnotebook'
- META_JSON_FILE =
'meta.json'
- JSON_KEY_NAME =
'name'
- JSON_KEY_UUID =
'uuid'
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#store_path ⇒ Object
Returns the value of attribute store_path.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #build_note(note_hash) ⇒ Object
- #file_with_path ⇒ Object
-
#initialize(attributes = nil) {|_self| ... } ⇒ Notebook
constructor
A new instance of Notebook.
- #meta_json_file ⇒ Object
- #meta_json_hash ⇒ Object
- #meta_json_string ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(attributes = nil) {|_self| ... } ⇒ Notebook
Returns a new instance of Notebook.
22 23 24 25 26 27 |
# File 'lib/quiver_toolbox/notebook.rb', line 22 def initialize(attributes = nil) attributes.each do |k, v| instance_variable_set("@#{k}", v) end if attributes yield self if block_given? end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
21 22 23 |
# File 'lib/quiver_toolbox/notebook.rb', line 21 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/quiver_toolbox/notebook.rb', line 21 def name @name end |
#store_path ⇒ Object
Returns the value of attribute store_path.
21 22 23 |
# File 'lib/quiver_toolbox/notebook.rb', line 21 def store_path @store_path end |
#uuid ⇒ Object
Returns the value of attribute uuid.
21 22 23 |
# File 'lib/quiver_toolbox/notebook.rb', line 21 def uuid @uuid end |
Class Method Details
.open(notebook_file) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/quiver_toolbox/notebook.rb', line 9 def self.open(notebook_file) = File.join(notebook_file, META_JSON_FILE) = JSON.load(File.open().read) new do |n| n.name = [JSON_KEY_NAME] n.uuid = [JSON_KEY_UUID] n.file = notebook_file end end |
Instance Method Details
#build_note(note_hash) ⇒ Object
77 78 79 80 81 |
# File 'lib/quiver_toolbox/notebook.rb', line 77 def build_note(note_hash) note = QuiverToolbox::Note.new(note_hash) note.notebook_path = file_with_path note end |
#file_with_path ⇒ Object
45 46 47 |
# File 'lib/quiver_toolbox/notebook.rb', line 45 def file_with_path @file_with_path ||= File.join("#{store_path}", file) end |
#meta_json_file ⇒ Object
50 51 52 |
# File 'lib/quiver_toolbox/notebook.rb', line 50 def @meta_json_file ||= File.join(file_with_path, "meta.json") end |
#meta_json_hash ⇒ Object
55 56 57 58 59 60 |
# File 'lib/quiver_toolbox/notebook.rb', line 55 def { 'name' => @name, 'uuid' => @uuid } end |
#meta_json_string ⇒ Object
63 64 65 |
# File 'lib/quiver_toolbox/notebook.rb', line 63 def JSON.pretty_generate() end |
#store ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/quiver_toolbox/notebook.rb', line 68 def store FileUtils.mkdir_p(file_with_path) File.open(, 'w') do |f| f.puts end self end |