Class: QuiverToolbox::Note
- Inherits:
-
Object
- Object
- QuiverToolbox::Note
- Defined in:
- lib/quiver_toolbox/note.rb
Constant Summary collapse
- EXTENSION =
'qvnote'
- META_JSON_FILE_NAME =
'meta.json'
- CONTENT_JSON_FILE_NAME =
'content.json'
- KEY_CREATED_AT =
'created_at'
- KEY_TAGS =
'tags'
- KEY_TITLE =
'title'
- KEY_UPDATED_AT =
'updated_at'
- KEY_UUID =
'uuid'
- KEY_CELLS =
'cells'
- JSON_KEYS =
[ KEY_CREATED_AT, KEY_TAGS, KEY_TITLE, KEY_UPDATED_AT, KEY_UUID, KEY_CELLS ]
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#notebook_path ⇒ Object
Returns the value of attribute notebook_path.
Class Method Summary collapse
Instance Method Summary collapse
- #content_json_file ⇒ Object
- #content_json_hash ⇒ Object
- #content_json_string ⇒ Object
- #file_name ⇒ Object
- #file_name_with_path ⇒ Object
-
#initialize(attributes = nil) {|_self| ... } ⇒ Note
constructor
A new instance of Note.
- #meta_json_file ⇒ Object
- #meta_json_hash ⇒ Object
- #meta_json_string ⇒ Object
- #store ⇒ Object
- #store_content_json(store_file = content_json_file) ⇒ Object
- #store_meta_json(store_file = meta_json_file) ⇒ Object
Constructor Details
#initialize(attributes = nil) {|_self| ... } ⇒ Note
Returns a new instance of Note.
45 46 47 48 49 50 |
# File 'lib/quiver_toolbox/note.rb', line 45 def initialize(attributes = nil) attributes.each do |k, v| send("#{k.to_s}=", v) if respond_to?("#{k.to_s}=") end if attributes yield self if block_given? end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
44 45 46 |
# File 'lib/quiver_toolbox/note.rb', line 44 def file @file end |
#notebook_path ⇒ Object
Returns the value of attribute notebook_path.
44 45 46 |
# File 'lib/quiver_toolbox/note.rb', line 44 def notebook_path @notebook_path end |
Class Method Details
.open(note_file_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quiver_toolbox/note.rb', line 24 def self.open(note_file_path) dir = note_file_path content_json_file = File.join(dir, 'content.json') content_json = JSON.load(File.open(content_json_file).read) = File.join(dir, 'meta.json') = JSON.load(File.open().read) QuiverToolbox::Note.new do |n| n.created_at = ['created_at'] n. = ['tags'] n.title = ['title'] n.updated_at = ['updated_at'] n.uuid = ['uuid'] n.cells = content_json['cells'] end end |
Instance Method Details
#content_json_file ⇒ Object
89 90 91 |
# File 'lib/quiver_toolbox/note.rb', line 89 def content_json_file File.join(file_name_with_path, CONTENT_JSON_FILE_NAME) end |
#content_json_hash ⇒ Object
94 95 96 97 98 99 |
# File 'lib/quiver_toolbox/note.rb', line 94 def content_json_hash { KEY_TITLE => @title, KEY_CELLS => @cells } end |
#content_json_string ⇒ Object
102 103 104 |
# File 'lib/quiver_toolbox/note.rb', line 102 def content_json_string JSON.pretty_generate(content_json_hash) end |
#file_name ⇒ Object
53 54 55 |
# File 'lib/quiver_toolbox/note.rb', line 53 def file_name "#{uuid}.#{EXTENSION}" end |
#file_name_with_path ⇒ Object
63 64 65 |
# File 'lib/quiver_toolbox/note.rb', line 63 def file_name_with_path File.join(notebook_path, file_name) end |
#meta_json_file ⇒ Object
68 69 70 |
# File 'lib/quiver_toolbox/note.rb', line 68 def File.join(file_name_with_path, META_JSON_FILE_NAME) end |
#meta_json_hash ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/quiver_toolbox/note.rb', line 73 def { KEY_CREATED_AT => @created_at, KEY_TAGS => @tags, KEY_TITLE => @title, KEY_UPDATED_AT => @updated_at, KEY_UUID => @uuid } end |
#meta_json_string ⇒ Object
84 85 86 |
# File 'lib/quiver_toolbox/note.rb', line 84 def JSON.pretty_generate() end |
#store ⇒ Object
107 108 109 110 |
# File 'lib/quiver_toolbox/note.rb', line 107 def store store_content_json end |
#store_content_json(store_file = content_json_file) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/quiver_toolbox/note.rb', line 122 def store_content_json(store_file = content_json_file) FileUtils.mkdir_p(file_name_with_path) File.open(store_file, 'w') do |f| f.puts content_json_string end self end |
#store_meta_json(store_file = meta_json_file) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/quiver_toolbox/note.rb', line 113 def (store_file = ) FileUtils.mkdir_p(file_name_with_path) File.open(store_file, 'w') do |f| f.puts end self end |