class QuiverToolbox::Note
Constants
- CONTENT_JSON_FILE_NAME
- EXTENSION
- JSON_KEYS
- KEY_CELLS
- KEY_CREATED_AT
- KEY_TAGS
- KEY_TITLE
- KEY_UPDATED_AT
- KEY_UUID
- META_JSON_FILE_NAME
- RESOURCES_DIR
Attributes
file[RW]
notebook_path[RW]
resources[R]
Public Class Methods
new(attributes = nil) { |self| ... }
click to toggle source
# File lib/quiver_toolbox/note.rb, line 53 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
open(note_file_path)
click to toggle source
# File lib/quiver_toolbox/note.rb, line 25 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) meta_json_file = File.join(dir, 'meta.json') meta_json = JSON.load(File.open(meta_json_file).read) notebook_path = nil Pathname.new(dir).ascend do |v| notebook_path = v.expand_path.to_s if v.basename.to_s.match('.qvnotebook') end QuiverToolbox::Note.new do |n| n.created_at = meta_json['created_at'] n.tags = meta_json['tags'] n.title = meta_json['title'] n.updated_at = meta_json['updated_at'] n.uuid = meta_json['uuid'] n.cells = content_json['cells'] n.notebook_path = notebook_path end end
Public Instance Methods
content_json_file()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 111 def content_json_file File.join(file_name_with_path, CONTENT_JSON_FILE_NAME) end
content_json_hash()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 116 def content_json_hash { KEY_TITLE => @title, KEY_CELLS => @cells } end
content_json_string()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 124 def content_json_string JSON.pretty_generate(content_json_hash) end
file_name()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 61 def file_name "#{uuid}.#{EXTENSION}" end
file_name_with_path()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 71 def file_name_with_path File.join(notebook_path, file_name) end
meta_json_file()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 90 def meta_json_file File.join(file_name_with_path, META_JSON_FILE_NAME) end
meta_json_hash()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 95 def meta_json_hash { KEY_CREATED_AT => @created_at, KEY_TAGS => @tags, KEY_TITLE => @title, KEY_UPDATED_AT => @updated_at, KEY_UUID => @uuid } end
meta_json_string()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 106 def meta_json_string JSON.pretty_generate(meta_json_hash) end
resources_dir()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 76 def resources_dir File.join(file_name_with_path, RESOURCES_DIR) end
src_resources=(src_files)
click to toggle source
# File lib/quiver_toolbox/note.rb, line 81 def src_resources=(src_files) @resources = [] src_files.each do |src_file| dist_file = File.join(resources_dir, "#{QuiverToolbox::Util.rename_to_uuid_file(src_file)}") @resources << {'src' => src_file, 'dist' => dist_file} end end
store()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 129 def store store_meta_json store_content_json store_resources if @resources self end
store_content_json(store_file = content_json_file)
click to toggle source
# File lib/quiver_toolbox/note.rb, line 155 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)
click to toggle source
# File lib/quiver_toolbox/note.rb, line 146 def store_meta_json(store_file = meta_json_file) FileUtils.mkdir_p(file_name_with_path) File.open(store_file, 'w') do |f| f.puts meta_json_string end self end
store_resources()
click to toggle source
# File lib/quiver_toolbox/note.rb, line 137 def store_resources FileUtils.mkdir_p(resources_dir) @resources.each do |hash| FileUtils.cp(hash['src'], hash['dist']) end self end