gexf 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,3 +19,7 @@ require 'graph'
19
19
  require 'xml_serializer'
20
20
  require 'document'
21
21
  require 'support'
22
+
23
+ def GEXF(thing)
24
+ GEXF::Document.parse(thing)
25
+ end
@@ -1,5 +1,14 @@
1
1
  class GEXF::Document < Nokogiri::XML::SAX::Document
2
2
 
3
+ def self.parse(thing)
4
+ document = self.new
5
+
6
+ ::Nokogiri::XML::SAX::Parser.new(document).
7
+ parse(thing.read)
8
+ thing.close
9
+ document.graph
10
+ end
11
+
3
12
  attr_reader :graph, :meta
4
13
 
5
14
  def start_document
@@ -63,6 +63,11 @@ class GEXF::Graph
63
63
  @attributes.dup
64
64
  end
65
65
 
66
+ def to_xml
67
+ serializer = GEXF::XmlSerializer.new(self)
68
+ serializer.serialize!
69
+ end
70
+
66
71
  private
67
72
  def assign_id(counter_name, id=nil)
68
73
  auto_id = @id_counter.send(counter_name) + 1
@@ -1,3 +1,3 @@
1
1
  module GEXF
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe GEXF::Document do
4
+
5
+ let(:filebody) { '...' }
6
+ let(:graph) { mock('graph') }
7
+ let(:file) { mock('file', :read => filebody, :close => nil) }
8
+
9
+ describe ".parse" do
10
+
11
+ subject { GEXF::Document.parse(file) }
12
+
13
+ it "instantiates a GEXF::Document, passes it to the sax parser, and calls parse" do
14
+ parser = mock
15
+
16
+ Nokogiri::XML::SAX.stub(:new).
17
+ with(kind_of(GEXF::Document)).
18
+ and_return(parser)
19
+
20
+ parser.stub(:parse).with(file.read)
21
+ GEXF::Document.any_instance.stub(:graph).and_return(graph)
22
+
23
+ subject.should eq(graph)
24
+ end
25
+ end
26
+ end
@@ -169,4 +169,19 @@ describe GEXF::Graph do
169
169
  end
170
170
  end
171
171
  end
172
+
173
+ describe "to_xml" do
174
+ subject { graph.to_xml }
175
+
176
+ it "instantiates the XmlSerializer and calls #serialize!" do
177
+ xml = '...'
178
+ serializer = mock('serializer', :serialize! => xml)
179
+
180
+ GEXF::XmlSerializer.should_receive(:new).
181
+ with(graph).
182
+ and_return(serializer)
183
+
184
+ subject.should eq(xml)
185
+ end
186
+ end
172
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gexf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &20222520 !ruby/object:Gem::Requirement
16
+ requirement: &16749560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.5.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20222520
24
+ version_requirements: *16749560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &20222020 !ruby/object:Gem::Requirement
27
+ requirement: &16749060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.7.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20222020
35
+ version_requirements: *16749060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &20221560 !ruby/object:Gem::Requirement
38
+ requirement: &16748600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.10
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *20221560
46
+ version_requirements: *16748600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &20221100 !ruby/object:Gem::Requirement
49
+ requirement: &16748140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.9.2.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20221100
57
+ version_requirements: *16748140
58
58
  description: A library for parsing, manipulating, and exporting graphs in the GEXF
59
59
  format.
60
60
  email: andrea.giulio.fiore@gmail.com
@@ -80,6 +80,7 @@ files:
80
80
  - spec/gexf/edgeset_spec.rb
81
81
  - spec/gexf/nodeset_spec.rb
82
82
  - spec/gexf/node_spec.rb
83
+ - spec/gexf/document_spec.rb
83
84
  - spec/gexf/attribute/assignable_spec.rb
84
85
  - spec/gexf/attribute/definable_spec.rb
85
86
  - spec/gexf/attribute_spec.rb
@@ -116,6 +117,7 @@ test_files:
116
117
  - spec/gexf/edgeset_spec.rb
117
118
  - spec/gexf/nodeset_spec.rb
118
119
  - spec/gexf/node_spec.rb
120
+ - spec/gexf/document_spec.rb
119
121
  - spec/gexf/attribute/assignable_spec.rb
120
122
  - spec/gexf/attribute/definable_spec.rb
121
123
  - spec/gexf/attribute_spec.rb