Class | Core::Model::Knowledge |
In: |
core/model/knowledge.rb
|
Parent: | Object |
This object acts a local cache of the remote ActiveResources. Everytime a new revision is detected this cache is refreshed with copies of the remote objects.
categories | [RW] | |
nodes | [RW] | |
revision | [RW] |
Initialise the knowledge base. The revision is set to 0.
# File core/model/knowledge.rb, line 30 def initialize() @revision = 0 end
# File core/model/knowledge.rb, line 35 def categories=(category_list) @sorted_categories = {} @categories = category_list end
For a given category_id this method find the Category object in the local cache.
# File core/model/knowledge.rb, line 59 def category_find(category_id) if @sorted_categories.size.zero? @categories.each do |category| @sorted_categories[category.id] = category end end return @sorted_categories.fetch(category_id, Category.new(:name => 'error, this note does not have a category in the server!!')) end
For a given parent_id, this method returns an array containing all the direct children of the node whose id is parent_id
# File core/model/knowledge.rb, line 48 def node_children(parent_id) # FIXME: raname to children_of(parent_id) children = [] @nodes.each do |n| children << n if n.parent_id == parent_id end return children end
For a given node_id this method find the Node object in the local cache.
# File core/model/knowledge.rb, line 70 def node_find(node_id) if @sorted_nodes.size.zero? @nodes.each do |node| @sorted_nodes[node.id] = node end end return @sorted_nodes.fetch(node_id, Node.new(:label => 'error, this node does not exist in the server!!')) end