gviz 0.0.7 → 0.0.8

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.
@@ -47,15 +47,33 @@ class Gviz
47
47
  # When `id` includes '*'(asterisk), multiple edges are updated.
48
48
  #
49
49
  # add(:a => [:b, :c])
50
- # edge(:a_*, arrowhead:'none')
50
+ # edge('a_*', arrowhead:'none')
51
51
  #
52
52
  # is equivalent to:
53
53
  #
54
54
  # edge(:a_b, arrowhead:'none')
55
55
  # edge(:a_c, arrowhead:'none')
56
+ #
57
+ # You can draw two or more edges between a pair of nodes,
58
+ # by adding a identifier with a underscore after the edge id.
59
+ #
60
+ # gv.edge(:a_b)
61
+ # gv.edge(:a_b_1)
62
+ #
63
+ # This create two nodes between a, b nodes.
64
+ #
65
+ # You can define a endpoint to a node, by adding a point identifier
66
+ # with a colon after the each node. You must specify the identifiers
67
+ # it the label of the corresponding nodes.
68
+ #
69
+ # gv.edge("a:x_b:y")
70
+ # gv.node(:a, label:"<x> 1 | 2 | 3")
71
+ # gv.node(:b, label:"4 | 5 |<y> 6")
72
+ #
73
+ # The edge 'a-b' joins 1 of the node 'a' with 6 of the node 'b'.
56
74
  def edge(id, attrs={})
57
75
  if md = id.match(/\*/)
58
- return multiple_edge(md, attrs)
76
+ return multi_edge(md, attrs)
59
77
  end
60
78
 
61
79
  Edge[id, attrs].tap do |edge|
@@ -227,8 +245,8 @@ class Gviz
227
245
  join ? '[' + arr.join(',') + ']' : arr
228
246
  end
229
247
 
230
- def multiple_edge(md, attrs)
231
- st = [md.pre_match, md.post_match].detect { |e| !e.empty? }.delete('_')
248
+ def multi_edge(md, attrs)
249
+ st = (md.pre_match + md.post_match).delete('_')
232
250
  edges = edgeset.select { |edge| edge.nodes.include? st.intern }
233
251
  edges.each { |eg| edge eg.id, attrs }
234
252
  end
@@ -1,4 +1,13 @@
1
1
  class Numeric
2
+ # Return a normalized value of the receiver between 0.0 to 1.0.
3
+ #
4
+ # 5.norm(0..10).should eql 0.5
5
+ # 7.norm(5..10).should eql 0.4
6
+ #
7
+ # When the target range specified, the result is adjusted to the range.
8
+ #
9
+ # 5.norm(0..10, 0..20).should eql 10.0
10
+ #
2
11
  def norm(range, tgr=0.0..1.0)
3
12
  unit = (self - range.min) / (range.max - range.min).to_f
4
13
  unit * (tgr.max - tgr.min) + tgr.min
@@ -6,6 +15,8 @@ class Numeric
6
15
  end
7
16
 
8
17
  class Object
18
+ # Returns a uniq number of the object in symbol form.
19
+ # This is used for creating ids of node or edge.
9
20
  def to_id
10
21
  to_s.hash.to_s.intern
11
22
  end
@@ -1,3 +1,3 @@
1
1
  class Gviz
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-16 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec