class RbbtGraph

Attributes

aesthetics[RW]
associations[RW]
entities[RW]
knowledge_base[RW]
rules[RW]

Public Class Methods

new() click to toggle source
# File lib/rbbt/rest/graph.rb, line 4
def initialize
  @entities = {}
  @aesthetics = {}
  @associations = {}
  @rules = {}
end

Public Instance Methods

add_aesthetic(elem, info) click to toggle source
# File lib/rbbt/rest/graph.rb, line 37
def add_aesthetic(elem, info)
  @aesthetics[elem] ||= []
  @aesthetics[elem] << info
end
add_associations(associations, type = :edge) click to toggle source
# File lib/rbbt/rest/graph.rb, line 11
def add_associations(associations, type = :edge)
  @associations[type] ||= []
  @associations[type].concat associations.collect{|i| i }
  @associations[type].uniq!
  if AssociationItem === associations
    add_entities associations.target, associations.target_entity_type
    add_entities associations.source, associations.source_entity_type
  end
end
add_entities(entities, type = nil, entity_options = {}) click to toggle source
# File lib/rbbt/rest/graph.rb, line 21
def add_entities(entities, type = nil, entity_options = {})                                                   
  type = entities.base_entity.to_s if type.nil? and AnnotatedArray === entities
  raise "No type specified and entities are not Annotated, so could not guess" if type.nil? 
  if knowledge_base
    good_entities = knowledge_base.translate(entities, type).compact.uniq
  else
    good_entities = entities
  end
  @namespace ||= entities.organism if entities.respond_to? :organism       
  if @entities[type].nil?
    @entities[type] = good_entities
  else
    @entities[type].concat good_entities
  end
end
add_rule(elem, info) click to toggle source
# File lib/rbbt/rest/graph.rb, line 42
def add_rule(elem, info)
  @rules[elem] ||= []
  @rules[elem] << info
end
js_model() click to toggle source
# File lib/rbbt/rest/graph.rb, line 48
def js_model
  js_model = {:entities => {}, :associations => {}, :aes_rules => {}, :edge_aes_rules => {}, :rules => {}, :edge_rules => {}}
  @entities.each do |type, codes|                                                                                          
    info = codes.info if codes.respond_to? :info
    info ||= {}
    js_model[:entities][type] = {:codes => codes, :entity_type => type, :info => info}
  end
  @associations.each do |type, codes|
    info = codes.info if codes.respond_to? :info
    info ||= {}
    js_model[:associations][type] = {:codes => codes, :database => type, :info => info}
  end
  @aesthetics.each do |type, info|
    aes_rule_type = (type == :node ? :aes_rules : :edge_aes_rules)
    js_model[aes_rule_type] = info
  end
  @rules.each do |type, info|
    rule_type = (type == :node ? :rules : :edge_rules)
    js_model[rule_type] = info
  end
  js_model
end