Class: NodeTree

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dynalist/node_tree.rb

Constant Summary collapse

@@nodes =
[]

Class Method Summary collapse

Class Method Details

.add(nodes) ⇒ Object



18
19
20
21
# File 'lib/dynalist/node_tree.rb', line 18

def self.add(nodes)
  @@nodes << nodes
  @@nodes.flatten!
end

.clearObject



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

def self.clear
  @@nodes = []
end

.find_by(**query) ⇒ Object



23
24
25
# File 'lib/dynalist/node_tree.rb', line 23

def self.find_by(**query)
  @@nodes.find { |node| node.include(**query) }
end

.nodesObject



10
11
12
# File 'lib/dynalist/node_tree.rb', line 10

def self.nodes
  @@nodes
end

.where(**query) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dynalist/node_tree.rb', line 27

def self.where(**query)
  @@nodes.select do |node|
    query.all? do |key, value|
      if value.kind_of? Array
        value.any? { |v| node.include(**{key => v}) }
      else
        node.include(**{key => value})
      end
    end
  end
end