kyanite 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/0 start all Tests.bat +23 -0
  2. data/History.txt +4 -0
  3. data/License.txt +21 -0
  4. data/Manifest.txt +88 -0
  5. data/PostInstall.txt +4 -0
  6. data/README.txt +48 -0
  7. data/Rakefile.rb +79 -0
  8. data/init.rb +2 -0
  9. data/lib/kyanite.rb +39 -0
  10. data/lib/kyanite/array.rb +5 -0
  11. data/lib/kyanite/array/array.rb +172 -0
  12. data/lib/kyanite/array/array2.rb +140 -0
  13. data/lib/kyanite/array/matrix2.rb +120 -0
  14. data/lib/kyanite/array_of_enumerables.rb +2 -0
  15. data/lib/kyanite/array_of_numerics.rb +2 -0
  16. data/lib/kyanite/array_of_strings.rb +2 -0
  17. data/lib/kyanite/basics.rb +60 -0
  18. data/lib/kyanite/dictionary.rb +116 -0
  19. data/lib/kyanite/enumerable.rb +7 -0
  20. data/lib/kyanite/enumerable/enumerable_enumerables.rb +70 -0
  21. data/lib/kyanite/enumerable/enumerable_numerics.rb +171 -0
  22. data/lib/kyanite/enumerable/enumerable_strings.rb +58 -0
  23. data/lib/kyanite/enumerable/structure.rb +170 -0
  24. data/lib/kyanite/general.rb +8 -0
  25. data/lib/kyanite/general/callerutils.rb +128 -0
  26. data/lib/kyanite/general/classutils.rb +246 -0
  27. data/lib/kyanite/general/kernel.rb +105 -0
  28. data/lib/kyanite/general/nil.rb +64 -0
  29. data/lib/kyanite/general/object.rb +86 -0
  30. data/lib/kyanite/general/true_false.rb +65 -0
  31. data/lib/kyanite/general/undoable.rb +24 -0
  32. data/lib/kyanite/hash.rb +170 -0
  33. data/lib/kyanite/matrix2.rb +2 -0
  34. data/lib/kyanite/nil.rb +3 -0
  35. data/lib/kyanite/numeric.rb +4 -0
  36. data/lib/kyanite/numeric/float.rb +26 -0
  37. data/lib/kyanite/numeric/integer.rb +34 -0
  38. data/lib/kyanite/numeric/numeric.rb +45 -0
  39. data/lib/kyanite/operation.rb +5 -0
  40. data/lib/kyanite/operation/call_tracker.rb +69 -0
  41. data/lib/kyanite/operation/rake.rb +101 -0
  42. data/lib/kyanite/operation/regexp.rb +23 -0
  43. data/lib/kyanite/operation/unit_test.rb +53 -0
  44. data/lib/kyanite/optimizer.rb +119 -0
  45. data/lib/kyanite/rake.rb +2 -0
  46. data/lib/kyanite/range.rb +54 -0
  47. data/lib/kyanite/set.rb +219 -0
  48. data/lib/kyanite/smart_load_path.rb +2 -0
  49. data/lib/kyanite/string.rb +13 -0
  50. data/lib/kyanite/string/cast.rb +104 -0
  51. data/lib/kyanite/string/chars.rb +184 -0
  52. data/lib/kyanite/string/chars_const.rb +190 -0
  53. data/lib/kyanite/string/diff.rb +78 -0
  54. data/lib/kyanite/string/div.rb +19 -0
  55. data/lib/kyanite/string/include.rb +43 -0
  56. data/lib/kyanite/string/list.rb +84 -0
  57. data/lib/kyanite/string/mgsub.rb +35 -0
  58. data/lib/kyanite/string/nested.rb +253 -0
  59. data/lib/kyanite/string/random.rb +69 -0
  60. data/lib/kyanite/string/split.rb +136 -0
  61. data/lib/kyanite/symbol.rb +19 -0
  62. data/lib/kyanite/tree.rb +99 -0
  63. data/lib/kyanite/undoable.rb +2 -0
  64. data/lib/kyanite/unit_test.rb +2 -0
  65. data/test/_start_all.rb +17 -0
  66. data/test/array/test_array.rb +106 -0
  67. data/test/array/test_matrix2.rb +162 -0
  68. data/test/enumerable/test_enumerable_enumerables.rb +46 -0
  69. data/test/enumerable/test_enumerable_numerics.rb +93 -0
  70. data/test/enumerable/test_enumerable_strings.rb +22 -0
  71. data/test/enumerable/test_structure.rb +220 -0
  72. data/test/general/test_classutils.rb +45 -0
  73. data/test/general/test_nil.rb +44 -0
  74. data/test/general/test_object.rb +49 -0
  75. data/test/general/test_true_false.rb +28 -0
  76. data/test/numeric/test_numeric_integer.rb +28 -0
  77. data/test/string/test_cast.rb +108 -0
  78. data/test/string/test_chars.rb +255 -0
  79. data/test/string/test_diff.rb +95 -0
  80. data/test/string/test_list.rb +141 -0
  81. data/test/string/test_nested.rb +361 -0
  82. data/test/string/test_split.rb +187 -0
  83. data/test/test_dictionary.rb +128 -0
  84. data/test/test_hash.rb +59 -0
  85. data/test/test_optimizer.rb +150 -0
  86. data/test/test_range.rb +41 -0
  87. data/test/test_set.rb +210 -0
  88. data/test/test_tree.rb +94 -0
  89. metadata +217 -0
@@ -0,0 +1,8 @@
1
+
2
+ require 'kyanite/general/callerutils'
3
+ require 'kyanite/general/classutils'
4
+ require 'kyanite/general/kernel'
5
+ require 'kyanite/general/nil'
6
+ require 'kyanite/general/object'
7
+ require 'kyanite/general/true_false'
8
+ require 'kyanite/general/undoable'
@@ -0,0 +1,128 @@
1
+
2
+ require 'kyanite/string/include'
3
+
4
+ # ==Tools for Kernel#caller
5
+ #
6
+ class CallerUtils
7
+
8
+ # Untersucht den Call-Stack. Liefert die Größe des Stacks oder den letzten Eintrag.
9
+ #
10
+ # Options:
11
+ # :skip Ignoriere caller, die das angegebene Fragment enthalten (String oder Array)
12
+ # :mode Welche Art von Ergebnis soll geliefert werden?
13
+ # :caller (Standard) liefert den Caller,
14
+ # :size liefert die Größe das Call-Stacks
15
+ #
16
+ # Beispiel:
17
+ # CallerUtils.mycaller(:skip => ['perception', 'ruby\gems', 'ruby/gems', 'test/unit'])
18
+ # => "R:/_Eigene_Projekte_unter_SVN/kyanite/lib/kyanite/general/callerutils.rb:100"
19
+ #
20
+ def self.mycaller(options={})
21
+ skip = options[:skip] || []
22
+ skip = [skip] if skip.kind_of?(String)
23
+ mode = options[:mode] || :caller
24
+ result = nil
25
+ size = caller.size
26
+ if skip.empty?
27
+ return caller[0] if mode == :caller
28
+ return size if mode == :size
29
+ end
30
+ caller.each_with_index do | c, i |
31
+ #puts "caller=#{c}"
32
+ #puts "skip=#{skip.inspect_pp}"
33
+ next if c.include?(skip)
34
+ #puts "ok! \n"
35
+ if mode == :caller
36
+ result = c
37
+ elsif mode == :size
38
+ result = (size - i)
39
+ end # if mode
40
+ break
41
+ end # each caller
42
+ # puts "mycaller=#{result}"
43
+ result
44
+ end # def
45
+
46
+
47
+
48
+ # Ermittelt das Hauptverzeichnis eines Callers auf heuristischem Wege.
49
+ # Der Name des Hauptverzeichnisses entspricht meist dem Namen der Applikation oder Library.
50
+ #
51
+ # Beispiel:
52
+ # my_caller = CallerUtils.mycaller(:skip => ['perception', 'ruby\gems', 'ruby/gems', 'test/unit'])
53
+ # CallerUtils.mycaller_maindir(my_caller)
54
+ # => "R:/_Eigene_Projekte_unter_SVN/kyanite"
55
+ #
56
+ def self.mycaller_maindir(mycaller)
57
+ dir_caller =File.dirname(mycaller)
58
+ array_caller = dir_caller.split('/')
59
+ array_caller = dir_caller.split("\\") if array_caller.size == 1
60
+ #require 'pp'
61
+ #pp array_caller
62
+ indicatorfiles = %W{Init Boot History License Manifest Rakefile README ReadMe Readme Setup}
63
+ check = []
64
+ (-array_caller.size).upto(-1) do |lev|
65
+ indicatorfiles.each do | f |
66
+ next if array_caller[lev..lev] == '..'
67
+ check << array_caller[0..lev].join('/') + "/#{f}.rb"
68
+ check << array_caller[0..lev].join('/') + "/#{f}.txt"
69
+ check << array_caller[0..lev].join('/') + "/#{f}"
70
+ check << array_caller[0..lev].join('/') + "/#{f.downcase}.rb"
71
+ check << array_caller[0..lev].join('/') + "/#{f.downcase}.txt"
72
+ check << array_caller[0..lev].join('/') + "/#{f.downcase}"
73
+ end
74
+ end
75
+ #return check
76
+ maindir = ''
77
+ check.uniq.each do | try |
78
+ # puts "try #{try}"
79
+ maindir = try
80
+ break if File.exist?(try)
81
+ end
82
+ # puts "mycaller_maindir=#{File.dirname(maindir) }"
83
+ return File.dirname(maindir)
84
+ end
85
+
86
+
87
+ # def self.caller_full(options={})
88
+ # caller
89
+ # end
90
+
91
+
92
+ end # class
93
+
94
+
95
+
96
+ # ==================================================================================
97
+ # Ausprobieren
98
+ #
99
+ if $0 == __FILE__
100
+
101
+
102
+
103
+
104
+ require 'pp'
105
+ my_caller = CallerUtils.mycaller(:skip => ['perception', 'ruby\gems', 'ruby/gems', 'test/unit'])
106
+ my_maindir = CallerUtils.mycaller_maindir(my_caller) if my_caller
107
+ pp my_maindir
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ end
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
@@ -0,0 +1,246 @@
1
+
2
+
3
+ require 'facets/kernel/singleton_class' # Easy access to an object‘s "special" class, otherwise known as it‘s eigen or meta class.
4
+ require 'facets/class/descendents' # Methode descendents
5
+
6
+
7
+ #
8
+ # Class
9
+ #
10
+
11
+ class Class
12
+
13
+ # Vergleichsoperator: Alphabetisch.
14
+ def <=>(other)
15
+ ( ( self.to_s ) <=> ( other.to_s ) )
16
+ end
17
+
18
+
19
+ # Unscharfer Vergleich zweier Klassen, z.B. für Tests
20
+ def =~(other)
21
+ return true if self == other
22
+ return true if self.descendents.include?(other)
23
+ return true if other.descendents.include?(self)
24
+ return false
25
+ end
26
+
27
+ # <tt> self </tt>
28
+ def to_class
29
+ self
30
+ end
31
+
32
+
33
+ # Wandelt eine Klasse in einen Klassennamen um, der nur Kleinbuchstaben enthält.
34
+ #
35
+ # Tests siehe TestKyaniteClassutils
36
+ #
37
+ def to_classname
38
+ self.to_s.demodulize.underscore
39
+ end
40
+
41
+ end # class
42
+
43
+
44
+
45
+
46
+ #
47
+ # Symbol
48
+ #
49
+
50
+ class Symbol
51
+
52
+ # Wandelt einen String in einen Klassennamen.
53
+ # 'MeinModul::EineKlasse' => eine_klasse
54
+ #
55
+ # Tests und Beispiele siehe TestKyaniteClassutils
56
+ #
57
+ def to_classname
58
+ self.to_s.to_classname
59
+ end
60
+
61
+ # Wandelt einen Klassennamen in eine Klasse.
62
+ #
63
+ # Akzeptiert sowohl CamelCase als auch down_case.
64
+ #
65
+ # Tests und Beispiele siehe TestKyaniteClassutils
66
+ #
67
+ def to_class
68
+ self.to_s.to_class
69
+ end
70
+
71
+ end # class
72
+
73
+
74
+
75
+
76
+
77
+ #
78
+ # String
79
+ #
80
+
81
+ class String
82
+
83
+ # Wandelt einen Klassennamen in eine Klasse.
84
+ #
85
+ # Akzeptiert sowohl CamelCase als auch down_case.
86
+ #
87
+ # Tests und Beispiele siehe TestKyaniteClassutils
88
+ #
89
+ def to_class
90
+ self.camelize.constantize
91
+ rescue
92
+ return nil
93
+ end
94
+
95
+
96
+ # Wandelt einen String in einen Klassennamen.
97
+ # 'MeinModul::EineKlasse' => eine_klasse
98
+ #
99
+ # Tests und Beispiele siehe TestKyaniteClassutils
100
+ #
101
+ def to_classname
102
+ self.demodulize.underscore
103
+ end
104
+
105
+ end
106
+
107
+
108
+
109
+ #
110
+ # String, from ActiveSupport
111
+ #
112
+
113
+ #
114
+ # ActiveSupport
115
+ # --------------
116
+ #
117
+ # Copyright (c) 2005 David Heinemeier Hansson
118
+ #
119
+ # Permission is hereby granted, free of charge, to any person obtaining
120
+ # a copy of this software and associated documentation files (the
121
+ # "Software"), to deal in the Software without restriction, including
122
+ # without limitation the rights to use, copy, modify, merge, publish,
123
+ # distribute, sublicense, and/or sell copies of the Software, and to
124
+ # permit persons to whom the Software is furnished to do so, subject to
125
+ # the following conditions:
126
+ #
127
+ # The above copyright notice and this permission notice shall be
128
+ # included in all copies or substantial portions of the Software.
129
+ #
130
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
131
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
132
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
133
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
134
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
135
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
136
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
137
+ #++
138
+
139
+
140
+ class String
141
+
142
+
143
+ # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
144
+ #
145
+ # Changes '::' to '/' to convert namespaces to paths.
146
+ #
147
+ # Examples:
148
+ # "ActiveRecord".underscore # => "active_record"
149
+ # "ActiveRecord::Errors".underscore # => active_record/errors
150
+ # From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
151
+ #
152
+ def underscore
153
+ self.gsub(/::/, '/').
154
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
155
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
156
+ tr("-", "_").
157
+ downcase
158
+ end
159
+
160
+
161
+
162
+ # By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
163
+ # is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
164
+ #
165
+ # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
166
+ #
167
+ # Examples:
168
+ # "active_record".camelize # => "ActiveRecord"
169
+ # "active_record".camelize(:lower) # => "activeRecord"
170
+ # "active_record/errors".camelize # => "ActiveRecord::Errors"
171
+ # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
172
+ # From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
173
+ #
174
+ def camelize(first_letter_in_uppercase = true)
175
+ if first_letter_in_uppercase
176
+ self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
177
+ else
178
+ self.first + camelize(self)[1..-1]
179
+ end
180
+ end
181
+
182
+
183
+ # Removes the module part from the expression in the string.
184
+ #
185
+ # Examples:
186
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
187
+ # "Inflections".demodulize # => "Inflections"
188
+ # From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
189
+ #
190
+ def demodulize
191
+ self.gsub(/^.*::/, '')
192
+ end
193
+
194
+
195
+
196
+ # Tries to find a constant with the name specified in the argument string:
197
+ #
198
+ # "Module".constantize # => Module
199
+ # "Test::Unit".constantize # => Test::Unit
200
+ #
201
+ # The name is assumed to be the one of a top-level constant, no matter whether
202
+ # it starts with "::" or not. No lexical context is taken into account:
203
+ #
204
+ # C = 'outside'
205
+ # module M
206
+ # C = 'inside'
207
+ # C # => 'inside'
208
+ # "C".constantize # => 'outside', same as ::C
209
+ # end
210
+ #
211
+ # NameError is raised when the name is not in CamelCase or the constant is
212
+ # unknown.
213
+ # From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
214
+ #
215
+ def constantize
216
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
217
+ raise NameError, "#{self.inspect} is not a valid constant name!"
218
+ end
219
+
220
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
221
+ end
222
+
223
+ end # class
224
+
225
+
226
+ class NilClass
227
+ def camelize; nil; end
228
+ def constantize; nil; end
229
+ def demodulize; nil; end
230
+ def to_class; nil; end
231
+ def to_classname; ''; end
232
+ def underscore; nil; end
233
+ end
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
@@ -0,0 +1,105 @@
1
+
2
+ require 'facets/timer'
3
+ require 'rbconfig'
4
+
5
+ unless defined? WINDOWS
6
+ WINDOWS = /djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM ? RUBY_PLATFORM : false
7
+ end
8
+
9
+ unless defined? RUBYDIR
10
+ RUBYDIR = Config::CONFIG['prefix']
11
+ end
12
+
13
+
14
+ module KyaniteKernel
15
+
16
+ # Wiederholt einen Block so lange, bis die Zeit abgelaufen ist.
17
+ # Liefert die Anzahl der Durchläufe, die in dieser Zeit möglich waren.
18
+ # Alle Exceptions werden abgefangen (=> fehlerhafte Blöcke scheinen schneller zu laufen)
19
+ def repeat_n_seconds( n=1, &block )
20
+ timer = Timer.new(n)
21
+ begin
22
+ timer.start
23
+ count = 0
24
+ until false
25
+ count += 1
26
+ yield block
27
+ end
28
+ timer.stop
29
+ rescue TimeoutError
30
+ return count
31
+ rescue
32
+ return count
33
+ rescue
34
+ return count
35
+ end # begin
36
+ end # def
37
+
38
+
39
+
40
+ # Quelle: Rails http://api.rubyonrails.org/classes/Kernel.html#M001639
41
+ def silence_warnings
42
+ old_verbose, $VERBOSE = $VERBOSE, nil
43
+ yield
44
+ ensure
45
+ $VERBOSE = old_verbose
46
+ end
47
+
48
+
49
+ def smart_load_path(__file__ = nil)
50
+ __file__ = caller[0] unless __file__
51
+ dir_caller =File.dirname(__file__)
52
+ patharray = dir_caller.split('/')
53
+ patharray = dir_caller.split("\\") if patharray.size == 1
54
+ libpath = File.join(patharray)
55
+ patharray.size.times do |i|
56
+ break if File.directory?( File.join(patharray, 'lib') )
57
+ patharray << '..'
58
+ end
59
+ newpath = File.join(patharray,'lib')
60
+ if $:.include?(newpath)
61
+ return false
62
+ else
63
+ $:.unshift(newpath)
64
+ return true
65
+ end
66
+
67
+ end #def
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+ end # class
77
+
78
+ class Object
79
+ include KyaniteKernel
80
+ end
81
+
82
+
83
+ # ---------------------------------------------------------
84
+ # Ausprobieren
85
+ #
86
+ if $0 == __FILE__
87
+ require 'perception'
88
+ # pp RUBYDIR
89
+
90
+ smart_load_path(__FILE__)
91
+ $LOAD_PATH.each do |path|
92
+ puts path
93
+ end
94
+
95
+ end
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+