Class: GEXF::Graph
- Inherits:
-
Object
- Object
- GEXF::Graph
- Defined in:
- lib/gexf/graph.rb
Constant Summary collapse
- STRING =
:string
- INTEGER =
:integer
- IDTYPES =
[STRING, INTEGER]
- STATIC =
:static
- DYNAMIC =
:dynamic
- MODES =
[STATIC, DYNAMIC]
- EDGETYPES =
GEXF::Edge::TYPES
Instance Attribute Summary collapse
-
#defaultedgetype ⇒ Object
readonly
Returns the value of attribute defaultedgetype.
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#idtype ⇒ Object
readonly
Returns the value of attribute idtype.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #attribute_definitions ⇒ Object
- #create_edge(source, target, opts = {}) ⇒ Object
- #create_node(opts = {}) ⇒ Object
- #define_edge_attribute(title, opts = {}) ⇒ Object
- #define_node_attribute(title, opts = {}) ⇒ Object
- #defined_attributes ⇒ Object
-
#initialize(opts = {}) ⇒ Graph
constructor
A new instance of Graph.
- #to_xml ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Graph
Returns a new instance of Graph.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gexf/graph.rb', line 15 def initialize(opts={}) edgetype = opts[:defaultedgetype] || GEXF::Edge::UNDIRECTED idtype = opts[:idtype] || STRING mode = opts[:mode] || STATIC id_counter = Struct.new(:nodes, :edges, :attributes) raise ArgumentError.new "Invalid defaultedgetype: '#{edgetype}'" unless EDGETYPES.include?(edgetype) raise ArgumentError.new "Invalid idtype: '#{idtype}'" unless IDTYPES.include?(idtype) raise ArgumentError.new "Invalid mode: '#{mode}'" unless MODES.include?(mode) @defaultedgetype = edgetype @idtype = idtype @mode = mode @id_counter = id_counter.new(0,0,0) @attributes = {} @nodes = GEXF::NodeSet.new @edges = GEXF::EdgeSet.new end |
Instance Attribute Details
#defaultedgetype ⇒ Object (readonly)
Returns the value of attribute defaultedgetype.
13 14 15 |
# File 'lib/gexf/graph.rb', line 13 def defaultedgetype @defaultedgetype end |
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
13 14 15 |
# File 'lib/gexf/graph.rb', line 13 def edges @edges end |
#idtype ⇒ Object (readonly)
Returns the value of attribute idtype.
13 14 15 |
# File 'lib/gexf/graph.rb', line 13 def idtype @idtype end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
13 14 15 |
# File 'lib/gexf/graph.rb', line 13 def mode @mode end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
13 14 15 |
# File 'lib/gexf/graph.rb', line 13 def nodes @nodes end |
Instance Method Details
#attribute_definitions ⇒ Object
62 63 64 |
# File 'lib/gexf/graph.rb', line 62 def attribute_definitions @attributes.dup end |
#create_edge(source, target, opts = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/gexf/graph.rb', line 55 def create_edge(source, target, opts={}) opts[:type] ||= defaultedgetype id = assign_id(:edges, opts.delete(:id)) @edges << edge = GEXF::Edge.new(id, source.id, target.id, opts.merge(:graph => self)) edge end |
#create_node(opts = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/gexf/graph.rb', line 49 def create_node(opts={}) id = assign_id(:nodes, opts.delete(:id)) @nodes << node = GEXF::Node.new(id, self, opts) node end |
#define_edge_attribute(title, opts = {}) ⇒ Object
44 45 46 47 |
# File 'lib/gexf/graph.rb', line 44 def define_edge_attribute(title, opts={}) id = assign_id(:attributes, opts.delete(:id)).to_s @edges.define_attribute(id, title, opts) end |
#define_node_attribute(title, opts = {}) ⇒ Object
39 40 41 42 |
# File 'lib/gexf/graph.rb', line 39 def define_node_attribute(title, opts={}) id = assign_id(:attributes, opts.delete(:id)).to_s @nodes.define_attribute(id, title, opts) end |
#defined_attributes ⇒ Object
35 36 37 |
# File 'lib/gexf/graph.rb', line 35 def defined_attributes nodes.defined_attributes.merge(edges.defined_attributes) end |
#to_xml ⇒ Object
66 67 68 69 |
# File 'lib/gexf/graph.rb', line 66 def to_xml serializer = GEXF::XmlSerializer.new(self) serializer.serialize! end |