Class: Yinx::NoteMeta

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

Class Method Summary collapse

Instance Method Summary collapse

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 meta, note_store
  @meta = meta
  @store = note_store
end

Instance Attribute Details

#tagsObject



25
26
27
# File 'lib/yinx/note_meta.rb', line 25

def tags
  @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

#bookObject



29
30
31
# File 'lib/yinx/note_meta.rb', line 29

def book
  @book ||= @store.book_name notebookGuid
end

#created_atObject



37
38
39
# File 'lib/yinx/note_meta.rb', line 37

def created_at
  Time.at created / 1000
end

#marshal_dumpObject



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

#stackObject



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_hObject



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_tagsObject



69
70
71
72
73
74
75
76
77
# File 'lib/yinx/note_meta.rb', line 69

def unwind_tags
  if tags.empty?
    [_unwind_tags(NoTagGuid, NoTag)]
  else
    tagGuids.zip(tags).map do |tag_id, tag_name|
      _unwind_tags tag_id, tag_name
    end
  end
end

#updated_atObject



41
42
43
# File 'lib/yinx/note_meta.rb', line 41

def updated_at
  Time.at updated / 1000
end