Class: Neo4j::Wrapper::Rule::Functions::Size

Inherits:
Function
  • Object
show all
Defined in:
lib/neo4j-wrapper/rule/functions/size.rb

Overview

A function for counting number of nodes of a given class.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#function_id, rule_node_property, #rule_node_property, #to_s, #value

Constructor Details

#initializeSize

Returns a new instance of Size.



8
9
10
11
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 8

def initialize
  @property = '_classname'
  @@lock ||= Java::java.lang.Object.new
end

Class Method Details

.function_nameObject



41
42
43
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 41

def self.function_name
  :size
end

Instance Method Details

#add(rule_name, rule_node, _) ⇒ Object



23
24
25
26
27
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 23

def add(rule_name, rule_node, _)
  key = rule_node_property(rule_name)
  rule_node[key] ||= 0
  rule_node[key] += 1
end

#calculate?(changed_property) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 13

def calculate?(changed_property)
  true
end

#classes_changed(rule_name, rule_node, class_change) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 33

def classes_changed(rule_name, rule_node, class_change)
  key = rule_node_property(rule_name)
  @@lock.synchronized do
    rule_node[key] ||= 0
    rule_node[key] += class_change.net_change
  end
end

#delete(rule_name, rule_node, _) ⇒ Object



17
18
19
20
21
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 17

def delete(rule_name, rule_node, _)
  key = rule_node_property(rule_name)
  rule_node[key] ||= 0
  rule_node[key] -= 1
end

#updateObject



29
30
31
# File 'lib/neo4j-wrapper/rule/functions/size.rb', line 29

def update(*)
  # we are only counting, not interested in property changes
end