Class: QuiverToolbox::Notebook

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) {|_self| ... } ⇒ Notebook

Returns a new instance of Notebook.

Yields:

  • (_self)

Yield Parameters:



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

#fileObject

Returns the value of attribute file.



21
22
23
# File 'lib/quiver_toolbox/notebook.rb', line 21

def file
  @file
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/quiver_toolbox/notebook.rb', line 21

def name
  @name
end

#store_pathObject

Returns the value of attribute store_path.



21
22
23
# File 'lib/quiver_toolbox/notebook.rb', line 21

def store_path
  @store_path
end

#uuidObject

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)
  meta_json_file = File.join(notebook_file, META_JSON_FILE)
  meta_json = JSON.load(File.open(meta_json_file).read)

  new do |n|
    n.name = meta_json[JSON_KEY_NAME]
    n.uuid = meta_json[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_pathObject



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_fileObject



50
51
52
# File 'lib/quiver_toolbox/notebook.rb', line 50

def meta_json_file
  @meta_json_file ||= File.join(file_with_path, "meta.json")
end

#meta_json_hashObject



55
56
57
58
59
60
# File 'lib/quiver_toolbox/notebook.rb', line 55

def meta_json_hash
  {
    'name' => @name,
    'uuid' => @uuid
  }
end

#meta_json_stringObject



63
64
65
# File 'lib/quiver_toolbox/notebook.rb', line 63

def meta_json_string
  JSON.pretty_generate(meta_json_hash)
end

#storeObject



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(meta_json_file, 'w') do |f|
    f.puts meta_json_string
  end
  self
end