Class: SocialFramework::NetworkHelper::GraphStrategy

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/social_framework/network_helper.rb

Overview

Define a Abstract Class to Network Graph

Direct Known Subclasses

GraphStrategyDefault

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#depthObject

Maximum depth graph



13
14
15
# File 'app/helpers/social_framework/network_helper.rb', line 13

def depth
  @depth
end

#networkObject

Array of verteces



11
12
13
# File 'app/helpers/social_framework/network_helper.rb', line 11

def network
  @network
end

Class Method Details

.get_instance(id, elements_factory) ⇒ Object

Get graph instance to user logged

Params:
id

Integer Id of the user logged

elements_factory

String Represent the factory class name to build

Returns Graph object



24
25
26
27
28
29
30
31
32
# File 'app/helpers/social_framework/network_helper.rb', line 24

def self.get_instance(id, elements_factory)
  @@instances ||= {}
  
  if @@instances[id].nil?
    @@instances[id] = GraphStrategyDefault.new elements_factory
  end

  return @@instances[id]
end

Instance Method Details

#build(root, attributes, relationships) ⇒ Object

Mount a graph from an user

Params:
root

User Root user to mount graph

attributes

Array Attributes will be added in vertex

relationships

Array labels to find relationships, can be multiple in array or just one in a simple String, default is “all” thats represents all relationships existing

Returns NotImplementedError



48
49
50
# File 'app/helpers/social_framework/network_helper.rb', line 48

def build(root, attributes, relationships)
  raise 'Must implement method in subclass'
end

#destroy(id) ⇒ Object

Destroy graph instance with id passed

Params:
id

Integer Id of the user logged

Returns Graph instance removed



38
39
40
# File 'app/helpers/social_framework/network_helper.rb', line 38

def destroy(id)
  @@instances.delete(id)
end

#search(map, search_in_progress, elements_number) ⇒ Object

Search users with values specified in a map

Params:
map

Hash with keys and values to compare

search_in_progress

Boolean to continue if true or start a new search

elements_number

Integer to limit max search result

Returns NotImplementedError



58
59
60
# File 'app/helpers/social_framework/network_helper.rb', line 58

def search(map, search_in_progress, elements_number)
  raise 'Must implement method in subclass'
end

#suggest_relationships(type_relationships, amount_relationships) ⇒ Object

Suggest relationships to root

Params:
type_relationships

Array labels to find relationships, can be multiple in array or just one in a simple String

amount_relationships

Integer quantity of relationships to suggest a new relationship

Returns NotImplementedError



67
68
69
# File 'app/helpers/social_framework/network_helper.rb', line 67

def suggest_relationships(type_relationships, amount_relationships)
  raise 'Must implement method in subclass'
end