facets 1.8.0 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
data/PROJECT CHANGED
@@ -30,20 +30,20 @@ changelog: doc/HISTORY.txt
30
30
 
31
31
  distribute: [ -doc/rdoc, -test/lib ]
32
32
 
33
- package: [ tar.gz, gem ]
33
+ package: [ gem, tgz ]
34
34
 
35
35
  rdoc:
36
36
  template : jamis
37
37
  options : ['--all', '--inline-source']
38
38
 
39
39
  mail:
40
- mailto : transfire@gmail.com #ruby-talk@ruby-lang.org
41
- from : transfire@gmail.com
40
+ mail_to : transfire@gmail.com #ruby-talk@ruby-lang.org
41
+ mail_from : transfire@gmail.com
42
42
  domain : facets.rubyforge.org
43
43
  server : smtp.gmail.com
44
44
  port : 25 #587
45
45
  account : transfire@gmail.com
46
- login : login #cram_md5 #plain
46
+ login_type : login #cram_md5 #plain
47
47
  secure : true
48
48
 
49
49
  announce_memo : 'doc/LATEST'
data/Rakefile CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
- #######################
3
- # Rakefile for Facets #
4
- #######################
5
- require 'project/project'
6
- project = Project.load
2
+
3
+ # Facets Rakefile
4
+
5
+ require '4rake/4rake'
6
+
7
+
8
+ #require 'project/project'
9
+ #project = Project.load
7
10
 
8
11
  #
9
12
  # Redirect, extact tests and run tests
10
13
  #
11
14
 
12
- task :prepare => [ :redirect, :extest, :test ]
15
+ #task :prepare => [ :redirect, :extest, :test ]
13
16
 
14
17
  #
15
18
  # Generate facet/ redirection files
@@ -47,20 +50,21 @@ end
47
50
  # Extract tests
48
51
  #
49
52
 
50
- desc "ectract units tests"
51
- task :extest do
52
- project.extract(:files=>'lib/facets/**/*.rb')
53
- end
53
+ #desc "ectract units tests"
54
+ #task :extest do
55
+ # project.extract(:files=>'lib/facets/**/*.rb')
56
+ #end
54
57
 
55
58
  #
56
59
  # Run tests
57
60
  #
58
61
 
59
- desc "run tests"
60
- task :test do
61
- project.test
62
- end
62
+ #desc "run tests"
63
+ #task :test do
64
+ # project.test
65
+ #end
63
66
 
67
+ =begin
64
68
  #
65
69
  # Generate API documentation
66
70
  #
@@ -92,6 +96,7 @@ task :rdoc_more do
92
96
  output: doc/rdoc/more
93
97
  END
94
98
  end
99
+ =end
95
100
 
96
101
  #
97
102
  # List core methods
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0 alpha (2007-01-24)
1
+ 1.8.8 rc (2007-01-30)
@@ -0,0 +1 @@
1
+ require 'facets/core/enumerable/cart.rb'
@@ -0,0 +1 @@
1
+ require 'facets/core/enumerable/cartesian_product.rb'
@@ -0,0 +1 @@
1
+ require 'facets/core/enumerable/self/cart.rb'
@@ -0,0 +1 @@
1
+ require 'facets/core/enumerable/self/cartesian_product.rb'
@@ -67,7 +67,8 @@ require 'facets/core/time/to_time'
67
67
  require 'facets/core/module/is'
68
68
  require 'facets/core/kernel/fn'
69
69
  require 'facets/core/kernel/here'
70
- require 'facets/core/kernel/own' # better name?
70
+ # TODO need a singleton method !!!
71
+ #require 'facets/core/kernel/own' # better name?
71
72
 
72
73
  # Convenience
73
74
  require 'facets/core/array/to_h'
@@ -1,3 +1,5 @@
1
+ require 'facets/core/dir/self/multiglob_recurse'
2
+
1
3
  # Summation glob. This is like multiglob but handles pattern
2
4
  # prefixes '+' and '-'. If the +files+ pattern list does not
3
5
  # start with a '+' or '-' entry, then the base is not included.
@@ -0,0 +1,119 @@
1
+ #--
2
+ # Cross product adapted from code by Michael Neuman.
3
+ #++
4
+
5
+ require 'generator'
6
+
7
+ module Enumerable
8
+
9
+ class << self
10
+
11
+ # Provides the cross-product of two or more Enumerables.
12
+ # This is the class-level method. The instance method
13
+ # calls on this.
14
+ #
15
+ # Enumerable.cross([1,2], [4], ["apple", "banana"])
16
+ # #=> [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
17
+ #
18
+ # Enumerable.cross([1,2], [3,4])
19
+ # #=> [[1, 3], [1, 4], [2, 3], [2, 4]]
20
+ #
21
+ #--
22
+ # TODO Make a more efficient version just for Array (?)
23
+ #++
24
+
25
+ def cartesian_product(*enums, &block)
26
+ raise if enums.empty?
27
+ gens = enums.map{|e| Generator.new(e)}
28
+ return [] if gens.any? {|g| g.end?}
29
+
30
+ sz = gens.size
31
+ res = []
32
+ tuple = Array.new(sz)
33
+
34
+ loop do
35
+ # fill tuple
36
+ (0 ... sz).each { |i|
37
+ tuple[i] = gens[i].current
38
+ }
39
+ if block.nil?
40
+ res << tuple.dup
41
+ else
42
+ block.call(tuple.dup)
43
+ end
44
+
45
+ # step forward
46
+ gens[-1].next
47
+ (sz-1).downto(0) do |i|
48
+ if gens[i].end?
49
+ if i > 0
50
+ gens[i].rewind
51
+ gens[i-1].next
52
+ else
53
+ return res
54
+ end
55
+ end
56
+ end
57
+ end #loop
58
+ end
59
+
60
+ alias :cart, :cartesian_product
61
+ end
62
+
63
+
64
+ # The instance level version of <tt>Enumerable::cartesian_product</tt>.
65
+ #
66
+ # a = []
67
+ # [1,2].cart([4,5]){|elem| a << elem }
68
+ # a #=> [[1, 4],[1, 5],[2, 4],[2, 5]]
69
+ #
70
+ #--
71
+ # TODO Make a more efficient version just for Array (?)
72
+ #++
73
+
74
+ def cart(*enums, &block)
75
+ Enumerable.cart(self, *enums, &block)
76
+ end
77
+
78
+ alias :cart, :cartesian_product
79
+ end
80
+
81
+
82
+
83
+ # _____ _
84
+ # |_ _|__ ___| |_
85
+ # | |/ _ \/ __| __|
86
+ # | | __/\__ \ |_
87
+ # |_|\___||___/\__|
88
+ #
89
+ =begin test
90
+
91
+ require 'test/unit'
92
+
93
+ class TCEnumerableClass < Test::Unit::TestCase
94
+
95
+ def test_cross
96
+ i = [[1,2], [3,4]]
97
+ o = [[1, 3], [1, 4], [2, 3], [2, 4]]
98
+ assert_equal( o, Enumerable.cart(*i) )
99
+ i = [[1,2], [4], ["apple", "banana"]]
100
+ o = [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
101
+ assert_equal( o, Enumerable.cart(*i) )
102
+ end
103
+
104
+ end
105
+
106
+
107
+ class TCEnumerable < Test::Unit::TestCase
108
+
109
+ def test_cross
110
+ a = [1,2,3].cart([4,5,6])
111
+ assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
112
+ a = []
113
+ [1,2,3].cart([4,5,6]) {|elem| a << elem }
114
+ assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
115
+ end
116
+
117
+ end
118
+
119
+ =end
@@ -0,0 +1,8 @@
1
+ # = cartesian_product.rb
2
+ #
3
+ # Stub for <tt>cart.rb</tt>.
4
+ #
5
+ # CREDIT Thomas Halfner (for the name correction from cross.rb)
6
+
7
+ require 'facets/core/enumerable/cart.rb'
8
+
@@ -0,0 +1,120 @@
1
+ # CREDIT Michael Neuman#
2
+ # CREDIT Thomas Halfner (name correction from cross.rb)
3
+ #
4
+ # Cross product adapted from code by Michael Neuman.
5
+
6
+ require 'generator'
7
+
8
+ module Enumerable
9
+
10
+ class << self
11
+
12
+ # Provides the cross-product of two or more Enumerables.
13
+ # This is the class-level method. The instance method
14
+ # calls on this.
15
+ #
16
+ # Enumerable.cross([1,2], [4], ["apple", "banana"])
17
+ # #=> [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
18
+ #
19
+ # Enumerable.cross([1,2], [3,4])
20
+ # #=> [[1, 3], [1, 4], [2, 3], [2, 4]]
21
+ #
22
+ #--
23
+ # TODO Make a more efficient version just for Array (?)
24
+ #++
25
+
26
+ def cartesian_product(*enums, &block)
27
+ raise if enums.empty?
28
+ gens = enums.map{|e| Generator.new(e)}
29
+ return [] if gens.any? {|g| g.end?}
30
+
31
+ sz = gens.size
32
+ res = []
33
+ tuple = Array.new(sz)
34
+
35
+ loop do
36
+ # fill tuple
37
+ (0 ... sz).each { |i|
38
+ tuple[i] = gens[i].current
39
+ }
40
+ if block.nil?
41
+ res << tuple.dup
42
+ else
43
+ block.call(tuple.dup)
44
+ end
45
+
46
+ # step forward
47
+ gens[-1].next
48
+ (sz-1).downto(0) do |i|
49
+ if gens[i].end?
50
+ if i > 0
51
+ gens[i].rewind
52
+ gens[i-1].next
53
+ else
54
+ return res
55
+ end
56
+ end
57
+ end
58
+ end #loop
59
+ end
60
+
61
+ alias :cart, :cartesian_product
62
+ end
63
+
64
+
65
+ # The instance level version of <tt>Enumerable::cartesian_product</tt>.
66
+ #
67
+ # a = []
68
+ # [1,2].cart([4,5]){|elem| a << elem }
69
+ # a #=> [[1, 4],[1, 5],[2, 4],[2, 5]]
70
+ #
71
+ #--
72
+ # TODO Make a more efficient version just for Array (?)
73
+ #++
74
+
75
+ def cart(*enums, &block)
76
+ Enumerable.cart(self, *enums, &block)
77
+ end
78
+
79
+ alias :cart, :cartesian_product
80
+ end
81
+
82
+
83
+
84
+ # _____ _
85
+ # |_ _|__ ___| |_
86
+ # | |/ _ \/ __| __|
87
+ # | | __/\__ \ |_
88
+ # |_|\___||___/\__|
89
+ #
90
+ =begin test
91
+
92
+ require 'test/unit'
93
+
94
+ class TCEnumerableClass < Test::Unit::TestCase
95
+
96
+ def test_cross
97
+ i = [[1,2], [3,4]]
98
+ o = [[1, 3], [1, 4], [2, 3], [2, 4]]
99
+ assert_equal( o, Enumerable.cart(*i) )
100
+ i = [[1,2], [4], ["apple", "banana"]]
101
+ o = [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
102
+ assert_equal( o, Enumerable.cart(*i) )
103
+ end
104
+
105
+ end
106
+
107
+
108
+ class TCEnumerable < Test::Unit::TestCase
109
+
110
+ def test_cross
111
+ a = [1,2,3].cart([4,5,6])
112
+ assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
113
+ a = []
114
+ [1,2,3].cart([4,5,6]) {|elem| a << elem }
115
+ assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
116
+ end
117
+
118
+ end
119
+
120
+ =end
@@ -0,0 +1,8 @@
1
+ # = cartesian_product.rb
2
+ #
3
+ # Stub for <tt>cart.rb</tt>.
4
+ #
5
+ # CREDIT Thomas Halfner (for the name correction from cross.rb)
6
+
7
+ require 'facets/core/enumerable/self/cart.rb'
8
+
@@ -53,7 +53,7 @@ class String
53
53
  inflection_rule 'ch' , '' , 'es' # search, switch
54
54
  inflection_rule 'ss' , '' , 'es' # process, address
55
55
  inflection_rule 'sh' , '' , 'es' # dish, wish
56
- inflection_rule 'qu' , 'y' , 'ies' # query, ability, agency
56
+ #inflection_rule 'qu' , 'y' , 'ies' # query, ability, agency
57
57
  inflection_rule 'hive' , '' , 's' # archive, hive
58
58
  inflection_rule 'sis' , '' , 'ses' # basis, diagnosis
59
59
  inflection_rule 't' , 'um' , 'a' # datum, medium, forum
@@ -75,12 +75,12 @@ class String
75
75
  inflection_rule 'test' , 'is' , 'es' # testis
76
76
  inflection_rule 'l' , 'f' , 'ves' # half halves
77
77
  inflection_rule '' , 'fe' , 'ves' # safe, wife
78
- inflection_rule 'a' , 'y' , 's' # query, ability, agency
79
- inflection_rule 'e' , 'y' , 's' # query, ability, agency
80
- inflection_rule 'i' , 'y' , 's' # query, ability, agency
81
- inflection_rule 'o' , 'y' , 's' # query, ability, agency
82
- inflection_rule 'u' , 'y' , 's' # query, ability, agency
83
- inflection_rule '' , 'y' , 'ies' # query, ability, agency
78
+ inflection_rule 'a' , 'y' , 'ys' # TODO Combine as a|e|i|o|u
79
+ inflection_rule 'e' , 'y' , 'ys' #
80
+ inflection_rule 'i' , 'y' , 'ys' #
81
+ inflection_rule 'o' , 'y' , 'ys' #
82
+ inflection_rule 'u' , 'y' , 'ys' #
83
+ inflection_rule '' , 'y' , 'ies' #
84
84
  inflection_rule '' , '' , 's' # --catch all--
85
85
 
86
86
  # Convert an English word from plurel to singular.
@@ -21,7 +21,7 @@
21
21
  # method defined, like how +desc+ annotates a rake +task+.
22
22
  #
23
23
  # TODO The ann(x).name notation is kind of nice. Would like to add that
24
- # back-in if reasonable. Basically this require heritage to be an OpenHash
24
+ # back-in if reasonable. Basically this require heritage to be an OpenObject
25
25
  # rather than just a hash.
26
26
  #
27
27
  # == Authors & Contributors
@@ -33,7 +33,7 @@
33
33
  # License:: Ruby License
34
34
 
35
35
  require 'facets/core/hash/to_h'
36
- require 'facets/core/hash/symbolize_keys'
36
+ require 'facets/core/hash/rekey'
37
37
  require 'facets/core/hash/op_add'
38
38
 
39
39
  # = Annotation
@@ -106,7 +106,7 @@ class Module
106
106
  if Hash === keys
107
107
  ref = ref.to_sym
108
108
  annotations[ref] ||= {}
109
- annotations[ref].update(keys.symbolize_keys)
109
+ annotations[ref].update(keys.rekey)
110
110
  else
111
111
  key = keys.to_sym
112
112
  heritage(ref)[key]
@@ -118,7 +118,8 @@ class Module
118
118
  # in the class or module's ancestors.
119
119
 
120
120
  def ann!( ref, keys_or_class=nil, keys=nil )
121
- return heritage(ref) unless keys_or_class or keys
121
+ #return heritage(ref) unless keys_or_class or keys
122
+ return annotations[ref] unless keys_or_class or keys
122
123
 
123
124
  if Class === keys_or_class
124
125
  keys ||= {}
@@ -130,7 +131,7 @@ class Module
130
131
  if Hash === keys
131
132
  ref = ref.to_sym
132
133
  annotations[ref] ||= {}
133
- annotations[ref].update(keys.symbolize_keys)
134
+ annotations[ref].update(keys.rekey)
134
135
  else
135
136
  key = keys.to_sym
136
137
  annotations[ref][key] = heritage(ref)[key].dup