Class: Yinx::NoteMeta
- Inherits:
-
Object
- Object
- Yinx::NoteMeta
- Defined in:
- lib/yinx/note_meta.rb
Constant Summary collapse
- OfficialApi =
[:updated, :created, :title, :notebookGuid, :guid, :contentLength, :tagGuids]
- FullApi =
OfficialApi + [:tags, :book, :stack]
Instance Attribute Summary collapse
- #tags ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #book ⇒ Object
- #created_at ⇒ Object
-
#initialize(meta, note_store) ⇒ NoteMeta
constructor
A new instance of NoteMeta.
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
- #stack ⇒ Object
- #to_h ⇒ Object
- #unwind_tags ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(meta, note_store) ⇒ NoteMeta
Returns a new instance of NoteMeta.
20 21 22 23 |
# File 'lib/yinx/note_meta.rb', line 20 def initialize , note_store @meta = @store = note_store end |
Instance Attribute Details
#tags ⇒ Object
25 26 27 |
# File 'lib/yinx/note_meta.rb', line 25 def @tags ||= (tagGuids ? tagGuids.map{|id| @store.tag_name id} : []) end |
Class Method Details
.from_h(hash) ⇒ Object
51 52 53 54 55 |
# File 'lib/yinx/note_meta.rb', line 51 def self.from_h hash raw = new nil, nil raw.marshal_load hash raw end |
Instance Method Details
#book ⇒ Object
29 30 31 |
# File 'lib/yinx/note_meta.rb', line 29 def book @book ||= @store.book_name notebookGuid end |
#created_at ⇒ Object
37 38 39 |
# File 'lib/yinx/note_meta.rb', line 37 def created_at Time.at created / 1000 end |
#marshal_dump ⇒ Object
57 58 59 |
# File 'lib/yinx/note_meta.rb', line 57 def marshal_dump to_h end |
#marshal_load(hash) ⇒ Object
61 62 63 64 65 |
# File 'lib/yinx/note_meta.rb', line 61 def marshal_load hash hash.each do |key, value| instance_variable_set "@#{key}", value end end |
#stack ⇒ Object
33 34 35 |
# File 'lib/yinx/note_meta.rb', line 33 def stack @stack = (instance_variable_defined? :@stack) ? @stack : @store.stack_name(notebookGuid) end |
#to_h ⇒ Object
45 46 47 48 49 |
# File 'lib/yinx/note_meta.rb', line 45 def to_h @h = FullApi.each_with_object({}) do |method, hash| hash[method] = send method end end |
#unwind_tags ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/yinx/note_meta.rb', line 69 def if .empty? [(NoTagGuid, NoTag)] else tagGuids.zip().map do |tag_id, tag_name| tag_id, tag_name end end end |
#updated_at ⇒ Object
41 42 43 |
# File 'lib/yinx/note_meta.rb', line 41 def updated_at Time.at updated / 1000 end |