Class: QuiverToolbox::Note
- Inherits:
-
Object
- Object
- QuiverToolbox::Note
- Defined in:
- lib/quiver_toolbox/note.rb
Constant Summary collapse
- EXTENSION =
'qvnote'- RESOURCES_DIR =
'resources/'- 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.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
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
- #resources_dir ⇒ Object
- #src_resources=(src_files) ⇒ Object
- #store ⇒ Object
- #store_content_json(store_file = content_json_file) ⇒ Object
- #store_meta_json(store_file = meta_json_file) ⇒ Object
- #store_resources ⇒ Object
Constructor Details
#initialize(attributes = nil) {|_self| ... } ⇒ Note
Returns a new instance of Note.
53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
51 52 53 |
# File 'lib/quiver_toolbox/note.rb', line 51 def file @file end |
#notebook_path ⇒ Object
Returns the value of attribute notebook_path.
51 52 53 |
# File 'lib/quiver_toolbox/note.rb', line 51 def notebook_path @notebook_path end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
52 53 54 |
# File 'lib/quiver_toolbox/note.rb', line 52 def resources @resources end |
Class Method Details
.open(note_file_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) = File.join(dir, 'meta.json') = JSON.load(File.open().read) notebook_path = nil Pathname.new(dir).ascend do |v| notebook_path = v..to_s if v.basename.to_s.match('.qvnotebook') end 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'] n.notebook_path = notebook_path end end |
Instance Method Details
#content_json_file ⇒ Object
111 112 113 |
# 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 ⇒ Object
116 117 118 119 120 121 |
# File 'lib/quiver_toolbox/note.rb', line 116 def content_json_hash { KEY_TITLE => @title, KEY_CELLS => @cells } end |
#content_json_string ⇒ Object
124 125 126 |
# File 'lib/quiver_toolbox/note.rb', line 124 def content_json_string JSON.pretty_generate(content_json_hash) end |
#file_name ⇒ Object
61 62 63 |
# File 'lib/quiver_toolbox/note.rb', line 61 def file_name "#{uuid}.#{EXTENSION}" end |
#file_name_with_path ⇒ Object
71 72 73 |
# File 'lib/quiver_toolbox/note.rb', line 71 def file_name_with_path File.join(notebook_path, file_name) end |
#meta_json_file ⇒ Object
90 91 92 |
# File 'lib/quiver_toolbox/note.rb', line 90 def File.join(file_name_with_path, META_JSON_FILE_NAME) end |
#meta_json_hash ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/quiver_toolbox/note.rb', line 95 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
106 107 108 |
# File 'lib/quiver_toolbox/note.rb', line 106 def JSON.pretty_generate() end |
#resources_dir ⇒ Object
76 77 78 |
# File 'lib/quiver_toolbox/note.rb', line 76 def resources_dir File.join(file_name_with_path, RESOURCES_DIR) end |
#src_resources=(src_files) ⇒ Object
81 82 83 84 85 86 87 |
# 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 ⇒ Object
129 130 131 132 133 134 |
# File 'lib/quiver_toolbox/note.rb', line 129 def store store_content_json store_resources if @resources self end |
#store_content_json(store_file = content_json_file) ⇒ Object
155 156 157 158 159 160 161 |
# 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) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/quiver_toolbox/note.rb', line 146 def (store_file = ) FileUtils.mkdir_p(file_name_with_path) File.open(store_file, 'w') do |f| f.puts end self end |
#store_resources ⇒ Object
137 138 139 140 141 142 143 |
# 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 |