nodus 0.3.1

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.
@@ -0,0 +1,97 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+
4
+ <svg width="478.6" height="79.8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
5
+ <!-- Generated at Tue Jul 1 01:34:54 2014 by:
6
+ Graph::Easy v0.75
7
+ Graph::Easy::As_svg v0.23
8
+ -->
9
+
10
+ <title>Untitled graph</title>
11
+ <defs>
12
+ <!-- open arrow -->
13
+ <g id="ah" stroke-linecap="round" stroke-width="1">
14
+ <line x1="-8" y1="-4" x2="1" y2="0" />
15
+ <line x1="1" y1="0" x2="-8" y2="4" />
16
+ </g>
17
+
18
+ <!-- class definitions -->
19
+ <style type="text/css"><![CDATA[
20
+ .edge {
21
+ font-size: 13px;
22
+ stroke: black;
23
+ text-align: center;
24
+ }
25
+ .graph {
26
+ font-size: 16px;
27
+ text-align: center;
28
+ }
29
+ .node,.node_source {
30
+ font-size: 16px;
31
+ text-align: center;
32
+ }
33
+ ]]></style>
34
+ </defs>
35
+
36
+ <!-- graph background with border (mainly for printing) -->
37
+ <rect x="0.5" y="0.5" width="476.6" height="77.8" fill="white" stroke="white" />
38
+
39
+ <g id="2" class="edge">
40
+ <!-- from g1 to a -->
41
+ <!-- horizontal -->
42
+ <line x1="62.04" y1="39.4" x2="117.36" y2="39.4" stroke="#000000" />
43
+ <use stroke="#000000" xlink:href="#ah" x="118.36" y="39.4"/>
44
+ </g>
45
+
46
+ <g id="4" class="edge">
47
+ <!-- from a to b -->
48
+ <!-- horizontal -->
49
+ <line x1="168.44" y1="39.4" x2="223.76" y2="39.4" stroke="#000000" />
50
+ <use stroke="#000000" xlink:href="#ah" x="224.76" y="39.4"/>
51
+ </g>
52
+
53
+ <g id="6" class="edge">
54
+ <!-- from b to c -->
55
+ <!-- horizontal -->
56
+ <line x1="274.84" y1="39.4" x2="330.16" y2="39.4" stroke="#000000" />
57
+ <use stroke="#000000" xlink:href="#ah" x="331.16" y="39.4"/>
58
+ </g>
59
+
60
+ <g id="8" class="edge">
61
+ <!-- from c to #7 -->
62
+ <!-- horizontal -->
63
+ <line x1="381.24" y1="39.4" x2="436.56" y2="39.4" stroke="#000000" />
64
+ <use stroke="#000000" xlink:href="#ah" x="437.56" y="39.4"/>
65
+ </g>
66
+
67
+ <g id="0" class="node_source">
68
+ <!-- g1, rect -->
69
+ <rect fill="#ffffff" height="43.8" stroke="#000000" width="37" x="17.5" y="17.5" />
70
+ <text x="36" y="45" style="font-family:serif" fill="#000000" text-anchor="middle">g1</text>
71
+ </g>
72
+
73
+ <g id="1" class="node">
74
+ <!-- a, circle -->
75
+ <circle cx="143.4" cy="39.4" fill="#ffffff" r="17.5" stroke="#000000" />
76
+ <text x="143" y="45" style="font-family:serif" fill="#000000" text-anchor="middle">a</text>
77
+ </g>
78
+
79
+ <g id="3" class="node">
80
+ <!-- b, circle -->
81
+ <circle cx="249.8" cy="39.4" fill="#ffffff" r="17.5" stroke="#000000" />
82
+ <text x="249" y="45" style="font-family:serif" fill="#000000" text-anchor="middle">b</text>
83
+ </g>
84
+
85
+ <g id="5" class="node">
86
+ <!-- c, circle -->
87
+ <circle cx="356.2" cy="39.4" fill="#ffffff" r="17.5" stroke="#000000" />
88
+ <text x="356" y="45" style="font-family:serif" fill="#000000" text-anchor="middle">c</text>
89
+ </g>
90
+
91
+ <g id="7" class="node_anon">
92
+ <!-- anon node #7, rect -->
93
+ <rect fill="#ffffff" height="44.8" width="16" x="444.6" y="17" />
94
+ <text x="452" y="45" fill="#000000" text-anchor="middle"></text>
95
+ </g>
96
+
97
+ </svg>
@@ -0,0 +1,4 @@
1
+ node { shape: circle; }
2
+ node.source { shape: rect; }
3
+
4
+ [ g1 ]{class:source;} --> [a] --> [b] --> [c] --> [ ]
@@ -0,0 +1,49 @@
1
+ digraph GRAPH_0 {
2
+
3
+ graph [ rankdir=LR ];
4
+ node [ shape=circle, fontname=Helvetica, color="#222222", fontcolor="#444444" ];
5
+ edge [ color="#555555", arrowsize=0.5 ]
6
+ rank=source
7
+ compound=true
8
+ color="#444444"
9
+
10
+ G [shape=trapezium,orientation=270,style=filled,fillcolor="#CCEEDD"]
11
+ B [shape=triangle,orientation=90,style=filled,fillcolor="#EEDDCC",label=""]
12
+ M [shape=triangle,orientation=270,style=filled,fillcolor="#EEDDCC",label=""]
13
+
14
+ // node [
15
+ // fillcolor=white,
16
+ // fontsize=11,
17
+ // shape=circle,
18
+ // style=filled ];
19
+
20
+ "#9" [ color="#ffffff", label=" ", style=filled ]
21
+
22
+ G -> a -> B
23
+ B -> b
24
+ B -> c
25
+ B -> d
26
+ B -> e
27
+ c -> M
28
+ d -> M
29
+ M -> "#9"
30
+ subgraph cluster0 {
31
+ e -> f -> g -> h
32
+ color="#DDDDDD"
33
+ }
34
+ subgraph cluster1 {
35
+ b -> x
36
+ color="#DDDDDD"
37
+ }
38
+
39
+ subgraph cluster2 {
40
+ d
41
+ color="#DDDDDD"
42
+ }
43
+ subgraph cluster3 {
44
+ c
45
+ color="#DDDDDD"
46
+ }
47
+ x -> M
48
+ h -> M
49
+ }
@@ -0,0 +1,163 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 2.36.0 (20140111.2315)
5
+ -->
6
+ <!-- Title: GRAPH_0 Pages: 1 -->
7
+ <svg width="674pt" height="256pt"
8
+ viewBox="0.00 0.00 674.00 256.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 252)">
10
+ <title>GRAPH_0</title>
11
+ <polygon fill="white" stroke="none" points="-4,4 -4,-252 670,-252 670,4 -4,4"/>
12
+ <g id="clust1" class="cluster"><title>cluster0</title>
13
+ <polygon fill="none" stroke="#dddddd" points="244,-128 244,-180 512,-180 512,-128 244,-128"/>
14
+ </g>
15
+ <g id="clust2" class="cluster"><title>cluster1</title>
16
+ <polygon fill="none" stroke="#dddddd" points="244,-188 244,-240 368,-240 368,-188 244,-188"/>
17
+ </g>
18
+ <g id="clust3" class="cluster"><title>cluster2</title>
19
+ <polygon fill="none" stroke="#dddddd" points="244,-8 244,-60 296,-60 296,-8 244,-8"/>
20
+ </g>
21
+ <g id="clust4" class="cluster"><title>cluster3</title>
22
+ <polygon fill="none" stroke="#dddddd" points="244,-68 244,-120 296,-120 296,-68 244,-68"/>
23
+ </g>
24
+ <!-- G -->
25
+ <g id="node1" class="node"><title>G</title>
26
+ <polygon fill="#cceedd" stroke="#222222" points="54,-113.488 54,-134.512 2.4869e-14,-142 3.55271e-15,-106 54,-113.488"/>
27
+ <text text-anchor="middle" x="27" y="-120.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">G</text>
28
+ </g>
29
+ <!-- a -->
30
+ <g id="node5" class="node"><title>a</title>
31
+ <ellipse fill="none" stroke="#222222" cx="108" cy="-124" rx="18" ry="18"/>
32
+ <text text-anchor="middle" x="108" y="-120.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">a</text>
33
+ </g>
34
+ <!-- G&#45;&gt;a -->
35
+ <g id="edge1" class="edge"><title>G&#45;&gt;a</title>
36
+ <path fill="none" stroke="#555555" d="M54.3059,-124C64.1525,-124 75.235,-124 84.6867,-124"/>
37
+ <polygon fill="#555555" stroke="#555555" points="84.7516,-125.75 89.7516,-124 84.7516,-122.25 84.7516,-125.75"/>
38
+ </g>
39
+ <!-- B -->
40
+ <g id="node2" class="node"><title>B</title>
41
+ <polygon fill="#eeddcc" stroke="#222222" points="162,-124 202.5,-106 202.5,-142 162,-124"/>
42
+ </g>
43
+ <!-- b -->
44
+ <g id="node6" class="node"><title>b</title>
45
+ <ellipse fill="none" stroke="#222222" cx="270" cy="-214" rx="18" ry="18"/>
46
+ <text text-anchor="middle" x="270" y="-210.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">b</text>
47
+ </g>
48
+ <!-- B&#45;&gt;b -->
49
+ <g id="edge3" class="edge"><title>B&#45;&gt;b</title>
50
+ <path fill="none" stroke="#555555" d="M202.693,-138.46C216.605,-154.309 238.918,-179.729 253.764,-196.643"/>
51
+ <polygon fill="#555555" stroke="#555555" points="252.755,-198.146 257.368,-200.749 255.385,-195.837 252.755,-198.146"/>
52
+ </g>
53
+ <!-- c -->
54
+ <g id="node7" class="node"><title>c</title>
55
+ <ellipse fill="none" stroke="#222222" cx="270" cy="-94" rx="18" ry="18"/>
56
+ <text text-anchor="middle" x="270" y="-90.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">c</text>
57
+ </g>
58
+ <!-- B&#45;&gt;c -->
59
+ <g id="edge4" class="edge"><title>B&#45;&gt;c</title>
60
+ <path fill="none" stroke="#555555" d="M202.693,-119.18C214.919,-114.537 233.633,-107.431 248.066,-101.95"/>
61
+ <polygon fill="#555555" stroke="#555555" points="248.728,-103.57 252.781,-100.159 247.485,-100.298 248.728,-103.57"/>
62
+ </g>
63
+ <!-- d -->
64
+ <g id="node8" class="node"><title>d</title>
65
+ <ellipse fill="none" stroke="#222222" cx="270" cy="-34" rx="18" ry="18"/>
66
+ <text text-anchor="middle" x="270" y="-30.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">d</text>
67
+ </g>
68
+ <!-- B&#45;&gt;d -->
69
+ <g id="edge5" class="edge"><title>B&#45;&gt;d</title>
70
+ <path fill="none" stroke="#555555" d="M202.693,-109.54C216.605,-93.6906 238.918,-68.2712 253.764,-51.357"/>
71
+ <polygon fill="#555555" stroke="#555555" points="255.385,-52.1633 257.368,-47.2511 252.755,-49.8544 255.385,-52.1633"/>
72
+ </g>
73
+ <!-- e -->
74
+ <g id="node9" class="node"><title>e</title>
75
+ <ellipse fill="none" stroke="#222222" cx="270" cy="-154" rx="18" ry="18"/>
76
+ <text text-anchor="middle" x="270" y="-150.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">e</text>
77
+ </g>
78
+ <!-- B&#45;&gt;e -->
79
+ <g id="edge6" class="edge"><title>B&#45;&gt;e</title>
80
+ <path fill="none" stroke="#555555" d="M202.693,-128.82C214.919,-133.463 233.633,-140.569 248.066,-146.05"/>
81
+ <polygon fill="#555555" stroke="#555555" points="247.485,-147.702 252.781,-147.841 248.728,-144.43 247.485,-147.702"/>
82
+ </g>
83
+ <!-- M -->
84
+ <g id="node3" class="node"><title>M</title>
85
+ <polygon fill="#eeddcc" stroke="#222222" points="594,-127 553.5,-145 553.5,-109 594,-127"/>
86
+ </g>
87
+ <!-- #9 -->
88
+ <g id="node4" class="node"><title>#9</title>
89
+ <ellipse fill="#ffffff" stroke="#ffffff" cx="648" cy="-127" rx="18" ry="18"/>
90
+ <text text-anchor="middle" x="648" y="-123.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444"> </text>
91
+ </g>
92
+ <!-- M&#45;&gt;#9 -->
93
+ <g id="edge9" class="edge"><title>M&#45;&gt;#9</title>
94
+ <path fill="none" stroke="#555555" d="M594.306,-127C604.153,-127 615.235,-127 624.687,-127"/>
95
+ <polygon fill="#555555" stroke="#555555" points="624.752,-128.75 629.752,-127 624.752,-125.25 624.752,-128.75"/>
96
+ </g>
97
+ <!-- a&#45;&gt;B -->
98
+ <g id="edge2" class="edge"><title>a&#45;&gt;B</title>
99
+ <path fill="none" stroke="#555555" d="M126.142,-124C135.111,-124 146.375,-124 156.824,-124"/>
100
+ <polygon fill="#555555" stroke="#555555" points="156.874,-125.75 161.874,-124 156.874,-122.25 156.874,-125.75"/>
101
+ </g>
102
+ <!-- x -->
103
+ <g id="node13" class="node"><title>x</title>
104
+ <ellipse fill="none" stroke="#222222" cx="342" cy="-214" rx="18" ry="18"/>
105
+ <text text-anchor="middle" x="342" y="-210.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">x</text>
106
+ </g>
107
+ <!-- b&#45;&gt;x -->
108
+ <g id="edge13" class="edge"><title>b&#45;&gt;x</title>
109
+ <path fill="none" stroke="#555555" d="M288.303,-214C297.543,-214 309.016,-214 318.895,-214"/>
110
+ <polygon fill="#555555" stroke="#555555" points="318.896,-215.75 323.896,-214 318.896,-212.25 318.896,-215.75"/>
111
+ </g>
112
+ <!-- c&#45;&gt;M -->
113
+ <g id="edge7" class="edge"><title>c&#45;&gt;M</title>
114
+ <path fill="none" stroke="#555555" d="M288.136,-95.9169C340.089,-101.729 495.503,-119.114 548.256,-125.015"/>
115
+ <polygon fill="#555555" stroke="#555555" points="548.155,-126.765 553.319,-125.581 548.545,-123.286 548.155,-126.765"/>
116
+ </g>
117
+ <!-- d&#45;&gt;M -->
118
+ <g id="edge8" class="edge"><title>d&#45;&gt;M</title>
119
+ <path fill="none" stroke="#555555" d="M287.281,-39.1326C338.416,-55.253 495.541,-104.788 548.423,-121.459"/>
120
+ <polygon fill="#555555" stroke="#555555" points="547.913,-123.133 553.208,-122.967 548.966,-119.795 547.913,-123.133"/>
121
+ </g>
122
+ <!-- f -->
123
+ <g id="node10" class="node"><title>f</title>
124
+ <ellipse fill="none" stroke="#222222" cx="342" cy="-154" rx="18" ry="18"/>
125
+ <text text-anchor="middle" x="342" y="-150.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">f</text>
126
+ </g>
127
+ <!-- e&#45;&gt;f -->
128
+ <g id="edge10" class="edge"><title>e&#45;&gt;f</title>
129
+ <path fill="none" stroke="#555555" d="M288.303,-154C297.543,-154 309.016,-154 318.895,-154"/>
130
+ <polygon fill="#555555" stroke="#555555" points="318.896,-155.75 323.896,-154 318.896,-152.25 318.896,-155.75"/>
131
+ </g>
132
+ <!-- g -->
133
+ <g id="node11" class="node"><title>g</title>
134
+ <ellipse fill="none" stroke="#222222" cx="414" cy="-154" rx="18" ry="18"/>
135
+ <text text-anchor="middle" x="414" y="-150.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">g</text>
136
+ </g>
137
+ <!-- f&#45;&gt;g -->
138
+ <g id="edge11" class="edge"><title>f&#45;&gt;g</title>
139
+ <path fill="none" stroke="#555555" d="M360.303,-154C369.543,-154 381.016,-154 390.895,-154"/>
140
+ <polygon fill="#555555" stroke="#555555" points="390.896,-155.75 395.896,-154 390.896,-152.25 390.896,-155.75"/>
141
+ </g>
142
+ <!-- h -->
143
+ <g id="node12" class="node"><title>h</title>
144
+ <ellipse fill="none" stroke="#222222" cx="486" cy="-154" rx="18" ry="18"/>
145
+ <text text-anchor="middle" x="486" y="-150.3" font-family="Helvetica,sans-Serif" font-size="14.00" fill="#444444">h</text>
146
+ </g>
147
+ <!-- g&#45;&gt;h -->
148
+ <g id="edge12" class="edge"><title>g&#45;&gt;h</title>
149
+ <path fill="none" stroke="#555555" d="M432.303,-154C441.543,-154 453.016,-154 462.895,-154"/>
150
+ <polygon fill="#555555" stroke="#555555" points="462.896,-155.75 467.896,-154 462.896,-152.25 462.896,-155.75"/>
151
+ </g>
152
+ <!-- h&#45;&gt;M -->
153
+ <g id="edge15" class="edge"><title>h&#45;&gt;M</title>
154
+ <path fill="none" stroke="#555555" d="M503.369,-148.406C516.455,-143.933 534.772,-137.673 548.218,-133.078"/>
155
+ <polygon fill="#555555" stroke="#555555" points="549.126,-134.617 553.291,-131.344 547.994,-131.305 549.126,-134.617"/>
156
+ </g>
157
+ <!-- x&#45;&gt;M -->
158
+ <g id="edge14" class="edge"><title>x&#45;&gt;M</title>
159
+ <path fill="none" stroke="#555555" d="M360.211,-214.4C392.115,-214.423 461.759,-211.06 512,-184 527.527,-175.637 541.152,-161.169 550.831,-148.903"/>
160
+ <polygon fill="#555555" stroke="#555555" points="552.296,-149.869 553.96,-144.839 549.523,-147.733 552.296,-149.869"/>
161
+ </g>
162
+ </g>
163
+ </svg>
@@ -0,0 +1 @@
1
+ 0.3.1
@@ -0,0 +1,162 @@
1
+ require 'ostruct'
2
+ require 'pathname'
3
+ require 'etc'
4
+ require 'set'
5
+ require 'digest'
6
+ require 'base64'
7
+ require 'pp'
8
+ #require 'excon'
9
+ require 'json'
10
+ require 'active_support/all'
11
+
12
+ # module Excon
13
+ # class Response
14
+ # def success?() @status && @status.to_s[0..0] == '2' end
15
+ # def payload
16
+ # @payload ||= case headers['Content-Type']
17
+ # when 'application/json' then JSON.parse(body)
18
+ # # when 'text/html' then # TODO: when needed, go ahead and give a parsed html as well (nokogiri or something)
19
+ # else body end
20
+ # end
21
+ # end
22
+ #
23
+ # class Connection
24
+ # def basic_url(more_params={})
25
+ # p = data.merge(more_params)
26
+ # "#{p[:scheme]}://#{p[:host]}/#{p[:path]}"
27
+ # end
28
+ #
29
+ # Excon::HTTP_VERBS.each do |method|
30
+ # class_eval <<-DEF, __FILE__, __LINE__ + 1
31
+ # def #{method}!(params={}, &block)
32
+ # rsp = #{method}(params, &block)
33
+ # raise(IOError, "#{method.to_s.upcase} %s returned a %s : %s" % [basic_url(params), rsp.status, rsp.inspect]) unless rsp.success?
34
+ # rsp
35
+ # end
36
+ # DEF
37
+ # end
38
+ # end
39
+ # end
40
+
41
+ class Set; alias_method :[],:member? end
42
+
43
+ unless defined?(Path)
44
+ Path = Pathname
45
+ class Pathname
46
+ def self.[](p) Path.new(p) end
47
+ alias old_init initialize
48
+ def initialize(*args) old_init(*args); @rc={}; @rc2={} end
49
+ alias_method :exists?,:exist?
50
+ def to_p() self end
51
+ def ** (p) self+p.to_p end
52
+ def r? () readable_real? end
53
+ def w? () writable_real? end
54
+ def x? () executable_real? end
55
+ def rw? () r? && w? end
56
+ def rwx?() r? && w? && x? end
57
+ def dir?() directory? end
58
+ def ===(p) real == p.real end
59
+ def perm?() exp.dir? ? rwx? : rw? end
60
+ def exp () return @exp ||= self.expand_path end
61
+ def real() begin exp.realpath rescue exp end end
62
+ def dir() (exp.dir? || to_s[-1].chr == '/') ? exp : exp.dirname end
63
+ def dir!() (exp.mkpath unless exp.dir? rescue return nil); self end
64
+ def glob(g,&b) Path.glob((dir + g.to_s).to_s, File::FNM_DOTMATCH, &b) end
65
+ def [](p) glob(p) end
66
+ #def [](p) Path.glob((dir + p.to_s).to_s, File::FNM_DOTMATCH) end
67
+ def older_than?(p) self.stat.mtime < p.stat.mtime end
68
+ def missing?() !self.exist? end
69
+ def as_other(new_dir, new_ext=nil)
70
+ p = new_dir.nil? ? self : (new_dir.to_p + self.basename)
71
+ p = Path[p.to_s.sub(/#{self.extname}$/,'.'+new_ext)] if new_ext
72
+ return p
73
+ end
74
+ def rel(p=nil,home=true)
75
+ p ||= ($pwd || Path.pwd)
76
+ return @rc2[p] if @rc2[p]
77
+ r = abs.rel_path_from(p.abs)
78
+ r = r.sub(ENV['HOME'],'~') if home
79
+ r
80
+ end
81
+ def different_contents?(str) IO.read(self).strip != str.strip end
82
+ def short(p=nil,home=true)
83
+ p ||= ($pwd || Path.pwd)
84
+ return @rc2[p.to_s] if @rc2[p.to_s]
85
+ sr = real; pr = p.real
86
+ se = exp; pe = p.exp
87
+ candidates = [sr.rel_path_from(pr), sr.rel_path_from(pe),
88
+ se.rel_path_from(pr), se.rel_path_from(pe)]
89
+ candidates += [sr.sub(ENV['HOME'],'~'), se.sub(ENV['HOME'],'~')] if home
90
+ @rc2[p.to_s] = candidates.sort_by{|v|v.to_s.size}[0]
91
+ end
92
+ def rel_path_from(p) @rc ||= {}; @rc[p.to_s] ||= relative_path_from(p) end
93
+ def relation_to(p)
94
+ travp = p.rel(self,false).to_s
95
+ if travp =~ /^(..\/)+..(\/|$)/ then :child
96
+ else travp =~ /^..\// ? :stranger : :parent end
97
+ end
98
+ def dist_from(p)
99
+ return 0 if self === p
100
+ travp = p.dir.rel(self.dir,false).to_s
101
+ return 1 if travp =~ /^\/?\.\/?$/
102
+ return travp.split('/').size + 1
103
+ end
104
+ #alias old_mm method_missing
105
+ #def method_missing(m,*a,&b) to_s.respond_to?(m) ? to_s.send(m,*a,&b) : old_mm(m,*a,&b) end
106
+ def abs(wd=nil)
107
+ wd ||= ($pwd || Path.pwd); wd = wd.to_s
108
+ s = self.to_s
109
+ raise ArgumentError.new('Bad working directory- must be absolute') if wd[0].chr != '/'
110
+ if s.blank? ; return nil
111
+ elsif s[0].chr=='/' ; return s
112
+ elsif s[0].chr=='~' && (s[1].nil?||s[1].chr=='/'); _abs_i(s[1..-1], ENV['HOME'])
113
+ elsif s =~ /~([^\/]+)/; _abs_i($', Etc.getpwnam($1).dir)
114
+ else _abs_i(s, wd) end
115
+ end
116
+
117
+ private
118
+ def _abs_i(p,wd)
119
+ str = wd + '/' + p ; last = str[-1].chr
120
+ combo = []
121
+ str.split('/').each do |part|
122
+ case part
123
+ when part.blank?, '.' then next
124
+ when '..' then combo.pop
125
+ else combo << part end
126
+ end
127
+ Path.new('/' + combo.join('/') + (last == '/' ? '/' : ''))
128
+ end
129
+ end
130
+
131
+ class String
132
+ def to_p() Path.new(self) end
133
+ #alias old_mm method_missing
134
+ #def method_missing(m,*a,&b) to_p.respond_to?(m) ? to_p.send(m,*a,&b) : old_mm(m,*a,&b) end
135
+ #def respond_to_missing?(m,p=false) to_p.respond_to?(m,p) end
136
+ def same_path(p) to_p === p end
137
+ end
138
+ end
139
+
140
+ class String
141
+ def last(n=1) self.size < n ? self : self[-n..-1] end
142
+ def numeric?() true if Float(self) rescue false end
143
+ end
144
+
145
+ class Fixnum
146
+ def numeric?() true end
147
+ def s(p=0,ch='0')
148
+ return ch if self == 0 && !ch.nil?
149
+ p > 0 ? ("%.#{p}f" % self) : self.to_s
150
+ end
151
+ end
152
+
153
+ class Float
154
+ def numeric?() true end
155
+ def s(p=2,ch='0')
156
+ return ch if self == 0.0 && p == 0 && !ch.nil?
157
+ v = self.round
158
+ v = (self > 0.0 ? self.ceil : self.floor) if v == 0 && !ch.nil?
159
+ ret = p > 0 ? ("%.#{p}f" % self) : v.to_s
160
+ (ret =~ /^0+(\.0+)?$/ && !ch.nil?) ? ch : ret
161
+ end
162
+ end