Class: UrlGraph
- Inherits:
-
RGL::ImplicitGraph
- Object
- RGL::ImplicitGraph
- UrlGraph
- Defined in:
- lib/graphiclious/url_graph.rb
Overview
UrlGraph models relations between tags
Instance Attribute Summary collapse
-
#filter_set ⇒ Object
Returns the value of attribute filter_set.
-
#fixed_dot_attributes ⇒ Object
Returns the value of attribute fixed_dot_attributes.
Class Method Summary collapse
- .ankor(url, name) ⇒ Object
- .edge_ankor(tag1, tag2, style = nil) ⇒ Object
- .edge_name(tag1, tag2) ⇒ Object
- .edge_url(tag1, tag2) ⇒ Object
- .intern_ankor(url, name, style = nil) ⇒ Object
- .node_ankor(tag, style = nil) ⇒ Object
- .node_url(tag) ⇒ Object
-
.tag2file(tag) ⇒ Object
some characters are not allowed in filenames and need to be replaced.
Instance Method Summary collapse
- #add_edge(tag, otherTag) ⇒ Object
- #add_vertex(vertex) ⇒ Object
- #d_quote(string) ⇒ Object
- #fixed_dot_edge_attributes ⇒ Object
- #fixed_dot_graph_attributes ⇒ Object
- #fixed_dot_node_attributes ⇒ Object
-
#initialize ⇒ UrlGraph
constructor
A new instance of UrlGraph.
-
#print_dotted_on_file(filename = 'graph.dot', params = {}) ⇒ Object
Output the DOT-graph to a file.
- #to_dot_graph(params = {}) ⇒ Object
Constructor Details
#initialize ⇒ UrlGraph
Returns a new instance of UrlGraph.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphiclious/url_graph.rb', line 20 def initialize @fixed_dot_attributes = DotAttributes.new @wrapped_graph = RGL::AdjacencyGraph.new @filter = proc { |v| @filter_set.nil? || @filter_set.include?(v) } @filter_set = nil super { |g| g.vertex_iterator { |b| @wrapped_graph.each_vertex { |v| b.call(v) if @filter.call(v) } } g.adjacent_iterator { |v, b| @wrapped_graph.each_adjacent(v) { |u| b.call(u) if @filter.call(u) } } } end |
Instance Attribute Details
#filter_set ⇒ Object
Returns the value of attribute filter_set.
18 19 20 |
# File 'lib/graphiclious/url_graph.rb', line 18 def filter_set @filter_set end |
#fixed_dot_attributes ⇒ Object
Returns the value of attribute fixed_dot_attributes.
18 19 20 |
# File 'lib/graphiclious/url_graph.rb', line 18 def fixed_dot_attributes @fixed_dot_attributes end |
Class Method Details
.ankor(url, name) ⇒ Object
51 52 53 |
# File 'lib/graphiclious/url_graph.rb', line 51 def self.ankor(url, name) "<a class=\"extern\" href=\"#{url}\" target=\"_top\">#{name}</a>" end |
.edge_ankor(tag1, tag2, style = nil) ⇒ Object
81 82 83 |
# File 'lib/graphiclious/url_graph.rb', line 81 def self.edge_ankor(tag1, tag2, style=nil) intern_ankor(edge_url(tag1, tag2), edge_name(tag1, tag2), style) end |
.edge_name(tag1, tag2) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/graphiclious/url_graph.rb', line 69 def self.edge_name(tag1, tag2) if tag1 <= tag2 tag1 + '-' + tag2 else tag2 + '-' + tag1 end end |
.edge_url(tag1, tag2) ⇒ Object
77 78 79 |
# File 'lib/graphiclious/url_graph.rb', line 77 def self.edge_url(tag1, tag2) node_url(edge_name(tag1, tag2)) end |
.intern_ankor(url, name, style = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/graphiclious/url_graph.rb', line 55 def self.intern_ankor(url, name, style=nil) link = "<a href=\"#{tag2file(url)}\">#{name}</a>" link = "<span class=\"#{style}\">#{link}</span>" unless style.nil? link end |
.node_ankor(tag, style = nil) ⇒ Object
65 66 67 |
# File 'lib/graphiclious/url_graph.rb', line 65 def self.node_ankor(tag, style=nil) intern_ankor(node_url(tag), tag, style) end |
.node_url(tag) ⇒ Object
61 62 63 |
# File 'lib/graphiclious/url_graph.rb', line 61 def self.node_url(tag) "#{tag2file(tag)}.htm" end |
.tag2file(tag) ⇒ Object
some characters are not allowed in filenames and need to be replaced
44 45 46 47 48 49 |
# File 'lib/graphiclious/url_graph.rb', line 44 def self.tag2file(tag) # Windows: \/:*?"<>| # Linux: () # Call to Graphviz: Space tag.gsub(/[\\\/:*?"<>|() ]/, '_') end |
Instance Method Details
#add_edge(tag, otherTag) ⇒ Object
39 40 41 |
# File 'lib/graphiclious/url_graph.rb', line 39 def add_edge(tag, otherTag) @wrapped_graph.add_edge(tag, otherTag) end |
#add_vertex(vertex) ⇒ Object
35 36 37 |
# File 'lib/graphiclious/url_graph.rb', line 35 def add_vertex(vertex) @wrapped_graph.add_vertex(vertex) end |
#d_quote(string) ⇒ Object
97 98 99 |
# File 'lib/graphiclious/url_graph.rb', line 97 def d_quote(string) "\"#{string}\"" end |
#fixed_dot_edge_attributes ⇒ Object
89 90 91 |
# File 'lib/graphiclious/url_graph.rb', line 89 def fixed_dot_edge_attributes fixed_dot_attributes.edge_attributes end |
#fixed_dot_graph_attributes ⇒ Object
93 94 95 |
# File 'lib/graphiclious/url_graph.rb', line 93 def fixed_dot_graph_attributes fixed_dot_attributes.graph_attributes end |
#fixed_dot_node_attributes ⇒ Object
85 86 87 |
# File 'lib/graphiclious/url_graph.rb', line 85 def fixed_dot_node_attributes fixed_dot_attributes.node_attributes end |
#print_dotted_on_file(filename = 'graph.dot', params = {}) ⇒ Object
Output the DOT-graph to a file.
129 130 131 132 133 |
# File 'lib/graphiclious/url_graph.rb', line 129 def print_dotted_on_file(filename = 'graph.dot', params = {}) File.open(filename, "w") {|f| print_dotted_on(params, f) } end |
#to_dot_graph(params = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/graphiclious/url_graph.rb', line 101 def to_dot_graph(params = {}) fixed_dot_graph_attributes.each { |k, v| params[k] ||= v } graph = (directed? ? DOT::DOTDigraph : DOT::DOTSubgraph).new(params) edge_class = directed? ? DOT::DOTDirectedEdge : DOT::DOTEdge dot_node_attributes = fixed_dot_node_attributes.clone each_vertex do |v| name = v.to_s dot_node_attributes['name'] = d_quote(name) dot_node_attributes['URL'] = d_quote(UrlGraph.node_url(name)) dot_node_attributes['label'] = name graph << DOT::DOTNode.new(dot_node_attributes) end dot_edge_attributes = fixed_dot_edge_attributes.clone each_edge do |u,v| tag1 = u.to_s tag2 = v.to_s dot_edge_attributes['from'] = d_quote(tag1) dot_edge_attributes['to'] = d_quote(tag2) dot_edge_attributes['URL'] = d_quote(UrlGraph.edge_url(tag1, tag2)) graph << edge_class.new(dot_edge_attributes) end graph end |