Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/dynalist/node.rb

Constant Summary collapse

COLOR =
{
  0 => :white,
  1 => :red,
  2 => :orange,
  3 => :yellow,
  4 => :green,
  5 => :blue,
  6 => :purple
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_id: nil, id: nil, content: nil, note: nil, created: nil, modified: nil, children: [], checked: false, checkbox: false, heading: 0, color: 0) ⇒ Node



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dynalist/node.rb', line 16

def initialize(file_id: nil, id: nil, content: nil, note: nil, created: nil, modified: nil, children: [], checked: false, checkbox: false, heading: 0, color: 0)
  @file_id = file_id
  @node_id = id
  @content = content
  @note = note
  @created = created
  @modified = modified
  @children_ids = children
  @checked = checked
  @checkbox = checkbox
  @heading = heading
  @color_number = color
end

Instance Attribute Details

#checkboxObject (readonly)

Returns the value of attribute checkbox.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def checkbox
  @checkbox
end

#checkedObject (readonly)

Returns the value of attribute checked.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def checked
  @checked
end

#childrenObject (readonly)

Returns the value of attribute children.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def children
  @children
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def content
  @content
end

#file_idObject (readonly)

Returns the value of attribute file_id.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def file_id
  @file_id
end

#headingObject (readonly)

Returns the value of attribute heading.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def heading
  @heading
end

#node_idObject (readonly)

Returns the value of attribute node_id.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def node_id
  @node_id
end

#noteObject (readonly)

Returns the value of attribute note.



14
15
16
# File 'lib/dynalist/node.rb', line 14

def note
  @note
end

Instance Method Details

#attributesObject



55
56
57
58
59
# File 'lib/dynalist/node.rb', line 55

def attributes
  instance_variables.map do |key|
    [key[1..-1].to_sym, instance_variable_get(key)]
  end.to_h
end

#colorObject



39
40
41
# File 'lib/dynalist/node.rb', line 39

def color
  COLOR[@color_number]
end

#created_atObject



47
48
49
# File 'lib/dynalist/node.rb', line 47

def created_at
  to_time(@created)
end

#include(**query) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dynalist/node.rb', line 30

def include(**query)
  query.each do |key, value|
    next if instance_variable_get("@#{key}") == value
    return false
  end

  return true
end

#updated_atObject



43
44
45
# File 'lib/dynalist/node.rb', line 43

def updated_at
  to_time(@modified)
end