rufus-dollar 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
 
2
2
  = rufus-dollar CHANGELOG.txt
3
3
 
4
+ == rufus-dollar - 1.0.2 released 2009/02/04
5
+
6
+ - code cleanup
7
+
4
8
 
5
9
  == rufus-dollar - 1.0.1 released 2008/02/19
6
10
 
data/README.txt CHANGED
@@ -6,7 +6,7 @@ A one-method library for substituting ${stuff} in text strings.
6
6
 
7
7
  == getting it
8
8
 
9
- sudo gem install rufus-dollar
9
+ sudo gem install rufus-dollar
10
10
 
11
11
  or at
12
12
 
@@ -15,23 +15,23 @@ http://rubyforge.org/frs/?group_id=4812
15
15
 
16
16
  == usage
17
17
 
18
- require 'rubygems'
19
- require 'rufus/dollar'
20
-
21
- h = {
22
- "name" => "Fred Brooks",
23
- "title" => "Silver Bullet",
24
- "left" => "na",
25
- "right" => "me",
26
- }
27
-
28
- puts Rufus::dsub "${name} wrote '${title}'", h
29
- # => "Fred Brooks wrote 'Silver Bullet'"
30
-
31
- # dollar notations are nestable
32
-
33
- puts Rufus::dsub "${${left}${right}}", h
34
- # => "${name}" => "Fred Brooks"
18
+ require 'rubygems'
19
+ require 'rufus/dollar'
20
+
21
+ h = {
22
+ 'name' => 'Fred Brooks',
23
+ 'title' => 'Silver Bullet',
24
+ 'left' => 'na',
25
+ 'right' => 'me',
26
+ }
27
+
28
+ puts Rufus::dsub "${name} wrote '${title}'", h
29
+ # => "Fred Brooks wrote 'Silver Bullet'"
30
+
31
+ # dollar notations are nestable
32
+
33
+ puts Rufus::dsub "${${left}${right}}", h
34
+ # => "${name}" => "Fred Brooks"
35
35
 
36
36
 
37
37
  == dependencies
@@ -43,7 +43,7 @@ None.
43
43
 
44
44
  On the rufus-ruby list[http://groups.google.com/group/rufus-ruby] :
45
45
 
46
- http://groups.google.com/group/rufus-ruby
46
+ http://groups.google.com/group/rufus-ruby
47
47
 
48
48
 
49
49
  == issue tracker
@@ -53,9 +53,9 @@ http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse
53
53
 
54
54
  == source
55
55
 
56
- http://rufus.rubyforge.org/svn/trunk/dollar
56
+ http://github.com/jmettraux/rufus-dollar
57
57
 
58
- svn checkout http://rufus.rubyforge.org/svn/trunk/dollar
58
+ git clone git://github.com/jmettraux/rufus-dollar.git
59
59
 
60
60
 
61
61
  == author
@@ -64,6 +64,11 @@ John Mettraux, jmettraux@gmail.com
64
64
  http://jmettraux.wordpress.com
65
65
 
66
66
 
67
+ == the rest of Rufus
68
+
69
+ http://rufus.rubyforge.org
70
+
71
+
67
72
  == license
68
73
 
69
74
  MIT
@@ -0,0 +1,3 @@
1
+
2
+ require 'rufus/dollar'
3
+
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2006-2008, John Mettraux, jmettraux@gmail.com
3
+ # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -8,10 +8,10 @@
8
8
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  # copies of the Software, and to permit persons to whom the Software is
10
10
  # furnished to do so, subject to the following conditions:
11
- #
11
+ #
12
12
  # The above copyright notice and this permission notice shall be included in
13
13
  # all copies or substantial portions of the Software.
14
- #
14
+ #
15
15
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -31,90 +31,65 @@
31
31
 
32
32
  module Rufus
33
33
 
34
- #
35
- # Performs 'dollar substitution' on a piece of text with a given
36
- # dictionary.
37
- #
38
- # require 'rubygems'
39
- # require 'rufus/dollar'
40
- #
41
- # h = {
42
- # "name" => "Fred Brooke",
43
- # "title" => "Silver Bullet"
44
- # }
45
- #
46
- # puts Rufus::dsub "${name} wrote '${title}'", h
47
- # # => "Fred Brooke wrote 'Silver Bullet'"
48
- #
49
- def self.dsub (text, dict, offset=nil)
50
-
51
- text = text.to_s
52
-
53
- #puts "### text is >#{text}<"
54
- #puts "### dict is of class #{dict.class.name}"
55
-
56
- j = text.index("}", offset || 0)
34
+ #
35
+ # Performs 'dollar substitution' on a piece of text with a given
36
+ # dictionary.
37
+ #
38
+ # require 'rubygems'
39
+ # require 'rufus/dollar'
40
+ #
41
+ # h = {
42
+ # "name" => "Fred Brooke",
43
+ # "title" => "Silver Bullet"
44
+ # }
45
+ #
46
+ # puts Rufus::dsub "${name} wrote '${title}'", h
47
+ # # => "Fred Brooke wrote 'Silver Bullet'"
48
+ #
49
+ def self.dsub (text, dict, offset=nil)
57
50
 
58
- return text if not j
51
+ text = text.to_s
59
52
 
60
- t = text[0, j]
53
+ j = text.index('}', offset || 0)
61
54
 
62
- i = t.rindex("${")
63
- ii = t.rindex("\\${")
55
+ return text unless j
64
56
 
65
- iii = t.rindex("{")
66
- iii = nil if offset
57
+ t = text[0, j]
67
58
 
68
- #puts "i is #{i}"
69
- #puts "j is #{j}"
70
- #puts "ii is #{ii}"
71
- #puts "iii is #{iii}"
59
+ i = t.rindex('${')
60
+ ii = t.rindex("\\${")
72
61
 
73
- return text if (not i)
74
- return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
62
+ iii = t.rindex('{')
63
+ iii = nil if offset
75
64
 
76
- return unescape(text) if (i) and (i != 0) and (ii == i-1)
77
- #
78
- # found "\${"
79
-
80
- key = text[i+2..j-1]
65
+ return text unless i
66
+ return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
81
67
 
82
- #puts "### key is '#{key}'"
68
+ return unescape(text) if (i) and (i != 0) and (ii == i-1)
69
+ #
70
+ # found "\${"
83
71
 
84
- value = dict[key]
72
+ key = text[i+2..j-1]
85
73
 
86
- #puts "### value 0 is '#{value}'"
74
+ value = dict[key]
87
75
 
88
- value = if value
89
- value.to_s
90
- else
91
- if dict.has_key?(key)
92
- "false"
93
- else
94
- ""
95
- end
96
- end
97
-
98
- #puts "### value 1 is '#{value}'"
99
-
100
- #puts "### pre is >#{text[0..i-1]}<"
101
- #puts "### post is >#{text[j+1..-1]}<"
76
+ value = if value
77
+ value.to_s
78
+ else
79
+ dict.has_key?(key) ? 'false' : ''
80
+ end
102
81
 
103
- pre = if i > 0
104
- text[0..i-1]
105
- else
106
- ""
107
- end
82
+ pre = (i > 0) ? text[0..i-1] : ''
108
83
 
109
- dsub "#{pre}#{value}#{text[j+1..-1]}", dict
110
- end
84
+ dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
85
+ end
111
86
 
112
- private
87
+ private
113
88
 
114
- def Rufus.unescape (text)
89
+ def self.unescape (text)
115
90
 
116
- text.gsub("\\\\\\$\\{", "\\${")
117
- end
91
+ text.gsub("\\\\\\$\\{", "\\${")
92
+ end
118
93
 
119
94
  end
120
95
 
@@ -8,77 +8,73 @@
8
8
  #
9
9
 
10
10
  require 'test/unit'
11
- require 'rufus/dollar'
12
- require 'test_base'
11
+ require File.dirname(__FILE__) + '/test_base'
13
12
 
14
- #
15
- # testing the 'dollar notation'
16
- #
17
13
 
18
14
  class DollarTest < Test::Unit::TestCase
19
- include TestBase
15
+ include TestBase
20
16
 
21
- #def setup
22
- #end
17
+ #def setup
18
+ #end
23
19
 
24
- #def teardown
25
- #end
20
+ #def teardown
21
+ #end
26
22
 
27
- def test_0
23
+ def test_0
28
24
 
29
- dict = {}
25
+ dict = {}
30
26
 
31
- dict['renard'] = 'goupil'
32
- dict['cane'] = 'oie'
33
- dict['oie blanche'] = 'poule'
27
+ dict['renard'] = 'goupil'
28
+ dict['cane'] = 'oie'
29
+ dict['oie blanche'] = 'poule'
34
30
 
35
- dotest "le petit renard", dict, "le petit renard"
36
- dotest "le petit {renard}", dict, "le petit {renard}"
37
- dotest "le petit ${renard}", dict, "le petit goupil"
38
- dotest "le petit ${renard} noir", dict, "le petit goupil noir"
31
+ dotest "le petit renard", dict, "le petit renard"
32
+ dotest "le petit {renard}", dict, "le petit {renard}"
33
+ dotest "le petit ${renard}", dict, "le petit goupil"
34
+ dotest "le petit ${renard} noir", dict, "le petit goupil noir"
39
35
 
40
- dotest "la grande ${${cane} blanche}", dict, "la grande poule"
36
+ dotest "la grande ${${cane} blanche}", dict, "la grande poule"
41
37
 
42
- dotest "le ${renard} et la ${cane}", dict, "le goupil et la oie"
43
- #
44
- # excuse my french...
38
+ dotest "le ${renard} et la ${cane}", dict, "le goupil et la oie"
39
+ #
40
+ # excuse my french...
45
41
 
46
- dotest "le \\${renard} encore", dict, "le \\${renard} encore"
42
+ dotest "le \\${renard} encore", dict, "le \\${renard} encore"
47
43
 
48
- dotest "", dict, ""
44
+ dotest "", dict, ""
49
45
 
50
- dotest("""
46
+ dotest("""
51
47
  """, dict, """
52
48
  """)
53
- dotest("""
49
+ dotest("""
54
50
  """, dict, """
55
51
  """)
56
- end
52
+ end
57
53
 
58
- def test_1
54
+ def test_1
59
55
 
60
- dict = {}
61
- dict['x'] = 'y'
56
+ dict = {}
57
+ dict['x'] = 'y'
62
58
 
63
- dotest "${x}", dict, "y"
64
- dotest "\\${x}", dict, "\\${x}"
65
- end
59
+ dotest "${x}", dict, "y"
60
+ dotest "\\${x}", dict, "\\${x}"
61
+ end
66
62
 
67
- def test_2
63
+ def test_2
68
64
 
69
- dict = {}
70
- dict['A'] = 'a'
71
- dict['B'] = 'b'
72
- dict['ab'] = 'ok'
65
+ dict = {}
66
+ dict['A'] = 'a'
67
+ dict['B'] = 'b'
68
+ dict['ab'] = 'ok'
73
69
 
74
- dotest "${${A}${B}}", dict, "ok"
75
- end
70
+ dotest "${${A}${B}}", dict, "ok"
71
+ end
76
72
 
77
- #def test_3
78
- # assert_equal OpenWFE.unescape("toto and ${toto}"), "toto and ${toto}"
79
- # assert_equal OpenWFE.unescape("toto & \${toto}"), "toto & ${toto}"
80
- # assert_equal "toto & \\${toto}", "toto & ${toto}"
81
- # #assert_equal OpenWFE.unescape('toto & \${toto}'), "toto & ${toto}"
82
- #end
73
+ #def test_3
74
+ # assert_equal OpenWFE.unescape("toto and ${toto}"), "toto and ${toto}"
75
+ # assert_equal OpenWFE.unescape("toto & \${toto}"), "toto & ${toto}"
76
+ # assert_equal "toto & \\${toto}", "toto & ${toto}"
77
+ # #assert_equal OpenWFE.unescape('toto & \${toto}'), "toto & ${toto}"
78
+ #end
83
79
 
84
80
  end
@@ -7,25 +7,24 @@
7
7
  # Mon Feb 18 23:32:12 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- require 'rufus/dollar'
12
- require 'test_base'
10
+ require File.dirname(__FILE__) + '/test_base'
11
+
13
12
 
14
13
  class NestedTest < Test::Unit::TestCase
15
- include TestBase
14
+ include TestBase
16
15
 
17
- #def setup
18
- #end
16
+ #def setup
17
+ #end
19
18
 
20
- #def teardown
21
- #end
19
+ #def teardown
20
+ #end
22
21
 
23
- def test_0
22
+ def test_0
24
23
 
25
- dotest " ${a${b}e} ", {}, " "
26
- dotest " ${a{b}e} ", {}, " "
27
- dotest "${a{b}e}", {}, ""
28
- dotest " \\${a{b}e} ", {}, " \\${a{b}e} "
29
- dotest "{a${b}c}", { "b" => 2 }, "{a2c}"
30
- end
24
+ dotest " ${a${b}e} ", {}, " "
25
+ dotest " ${a{b}e} ", {}, " "
26
+ dotest "${a{b}e}", {}, ""
27
+ dotest " \\${a{b}e} ", {}, " \\${a{b}e} "
28
+ dotest "{a${b}c}", { "b" => 2 }, "{a2c}"
29
+ end
31
30
  end
@@ -1,4 +1,4 @@
1
1
 
2
- require 'test/dollar_test'
3
- require 'test/nested_test'
2
+ require File.dirname(__FILE__) + '/dollar_test'
3
+ require File.dirname(__FILE__) + '/nested_test'
4
4
 
@@ -7,14 +7,21 @@
7
7
  # Mon Feb 18 23:30:37 JST 2008
8
8
  #
9
9
 
10
+ $:.unshift File.dirname(__FILE__) + '/../lib/'
11
+
12
+ require 'test/unit'
13
+ require 'rufus/dollar'
14
+
15
+
10
16
  module TestBase
11
17
 
12
- protected
18
+ protected
13
19
 
14
- def dotest (text, dict, target)
20
+ def dotest (text, dict, target)
15
21
 
16
- result = Rufus::dsub text, dict
22
+ result = Rufus.dsub(text, dict)
17
23
 
18
- assert_equal target, result
19
- end
24
+ assert_equal target, result
25
+ end
20
26
  end
27
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-dollar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-19 00:00:00 +09:00
12
+ date: 2009-02-04 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,6 +26,7 @@ extra_rdoc_files:
26
26
  files:
27
27
  - lib/rufus
28
28
  - lib/rufus/dollar.rb
29
+ - lib/rufus-dollar.rb
29
30
  - test/dollar_test.rb
30
31
  - test/nested_test.rb
31
32
  - test/test.rb
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  requirements: []
56
57
 
57
58
  rubyforge_project:
58
- rubygems_version: 0.9.5
59
+ rubygems_version: 1.3.1
59
60
  signing_key:
60
61
  specification_version: 2
61
62
  summary: ${xxx} substitutions