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,190 @@
1
+
2
+ # Multibyte-Unterstützung von ActiveSupport
3
+ $KCODE = 'UTF8'
4
+ require 'active_support'
5
+
6
+ require 'facets/dictionary'
7
+ require 'kyanite/nil'
8
+ require 'kyanite/string/div'
9
+
10
+
11
+
12
+
13
+ unless defined?(TR_UPCASE_ALL_REGEXP)
14
+ base = Dictionary.new
15
+ base['a'] = ' àáâă äãā åạą æ ảấầắằ а '
16
+ base['A'] = ' ÀÁÂĂ ÄÃĀ ÅẠĄ Æ ẢẤẦẮẰ А '
17
+ base['b'] = ' б '
18
+ base['B'] = ' Б '
19
+ base['c'] = ' ćĉč çċ цч '
20
+ base['C'] = ' ĆĈČ ÇĊ ЦЧ '
21
+ base['d'] = ' ď ðđ д '
22
+ base['D'] = ' Ď ÐĐ Д '
23
+ base['e'] = ' èéêěĕ ëēėę ế еэ '
24
+ base['E'] = ' ÈÉÊĚĔ ËĒĖĘ Ế ЕЭ '
25
+ base['f'] = ' ф '
26
+ base['F'] = ' Ф '
27
+ base['g'] = ' ĝğġ ģ г '
28
+ base['G'] = ' ĜĞĠ Ģ Г '
29
+ base['h'] = ' ĥħ х '
30
+ base['H'] = ' ĤĦ Х '
31
+ base['i'] = ' ìíîĭ ïĩīı į ij ий'
32
+ base['I'] = ' ÌÍÎĬ ÏĨĪİ Į IJ ИЙ'
33
+ base['j'] = ' ĵ юя '
34
+ base['J'] = ' Ĵ ЮЯ '
35
+ base['k'] = ' ķĸ к '
36
+ base['K'] = ' Ķĸ К '
37
+ base['l'] = ' ĺ ľłļŀ л '
38
+ base['L'] = ' Ĺ ĽŁĻĿ Л '
39
+ base['m'] = ' м '
40
+ base['M'] = ' М '
41
+ base['n'] = ' ńň ñņʼnŋ н '
42
+ base['N'] = ' ŃŇ ÑŅʼnŊ Н '
43
+ base['o'] = ' òóôŏ öõō øőơ œ о '
44
+ base['O'] = ' ÒÓÔŎ ÖÕŌ ØŐƠ Œ О '
45
+ base['p'] = ' п '
46
+ base['P'] = ' П '
47
+ base['q'] = nil
48
+ base['Q'] = nil
49
+ base['r'] = ' ŕř ŗ р '
50
+ base['R'] = ' ŔŘ Ŗ Р '
51
+ base['s'] = ' śŝš ßş сшщ '
52
+ base['S'] = ' ŚŜŠ ߪ СШЩ '
53
+ base['t'] = ' ţťŧþ т '
54
+ base['T'] = ' ŢŤŦÞ Т '
55
+ base['u'] = ' ùúûŭ üũū ůűųư у '
56
+ base['U'] = ' ÙÚÛŬ ÜŨŪ ŮŰŲƯ У '
57
+ base['v'] = ' в'
58
+ base['V'] = ' В '
59
+ base['w'] = ' ŵ '
60
+ base['W'] = ' Ŵ '
61
+ base['x'] = nil
62
+ base['X'] = nil
63
+ base['y'] = ' ýŷ ÿ '
64
+ base['Y'] = ' ÝŶ Ÿ '
65
+ base['z'] = ' źżž жз '
66
+ base['Z'] = ' ŹŻŽ ЖЗ '
67
+
68
+
69
+
70
+
71
+
72
+ allkeys = 'abcdefghijklmnopqrstuvwxyz'
73
+ #allkeys = 'snk'
74
+
75
+ # Spaces entfernen
76
+ allkeys.split(//).each do |key|
77
+ next unless base[key]
78
+ base[key].strip!.gsub!(' ','').gsub!(' ','')
79
+ base[key.upcase].strip!.gsub!(' ','').gsub!(' ','')
80
+ end
81
+
82
+
83
+ # upcase und downcase
84
+ tr_upcase = ''
85
+ tr_downcase = ''
86
+ allkeys.split(//).each do |key|
87
+ next unless base[key]
88
+ tr_downcase += base[key]
89
+ tr_upcase += base[key.upcase]
90
+ end
91
+
92
+ tr_upcase2 = ''
93
+ tr_downcase2 = ''
94
+ tr_downcase_only = ''
95
+ tr_upcase.mb_chars.split(//).each_with_index do |c, i|
96
+ if c == tr_downcase.mb_chars[i..i]
97
+ tr_downcase_only += c
98
+ else
99
+ tr_upcase2 += c
100
+ tr_downcase2 += tr_downcase.mb_chars[i..i]
101
+ end
102
+ end
103
+
104
+ TR_DOWNCASE_ONLY = tr_downcase_only
105
+
106
+
107
+ # reduce alphabet
108
+ tr_full = ''
109
+ tr_reduced = ''
110
+ allkeys.split(//).each do |key|
111
+ next unless base[key]
112
+ tr_full += base[key]
113
+ # tr_reduced += key * base[key].jsize
114
+ tr_reduced += key * base[key].mb_chars.size
115
+ tr_full += base[key.upcase]
116
+ # tr_reduced += key.upcase * base[key.upcase].jsize
117
+ tr_reduced += key.upcase * base[key.upcase].mb_chars.size
118
+ end
119
+
120
+ tr_full2 = ''
121
+ tr_reduced2 = ''
122
+ tr_full.mb_chars.split(//).each_with_index do |c, i|
123
+ next if ( TR_DOWNCASE_ONLY.include?(c) &&
124
+ (tr_reduced[i..i] == tr_reduced[i..i].upcase) )
125
+ tr_full2 += c
126
+ tr_reduced2 += tr_reduced[i..i]
127
+ end
128
+
129
+
130
+ TR_UPCASE = tr_upcase2
131
+ TR_DOWNCASE = tr_downcase2
132
+ TR_FULL = tr_full2
133
+ TR_REDUCED = tr_reduced2
134
+ TR_UPCASE_ALL_REGEXP = /^[A-ZÀÁÂĂÄÃĀÅẠĄÆẢẤẦẮẰАБĆĈČÇĊЦЧĎÐĐДÈÉÊĚĔËĒĖĘẾЕЭФĜĞĠĢГĤĦХÌÍÎĬÏĨĪİĮIJИЙĴЮЯĶКĹĽŁĻĿЛМŃŇÑŅŊНÒÓÔŎÖÕŌØŐƠŒОПŔŘŖРŚŜŠŞСШЩŢŤŦÞТÙÚÛŬÜŨŪŮŰŲƯУВŴÝŶŸŹŻŽЖЗ]/
135
+
136
+ end # unless defined?
137
+
138
+
139
+
140
+
141
+
142
+
143
+ # -----------------------------------------------------------------------------------------
144
+ # Ausprobieren
145
+ #
146
+ if $0 == __FILE__ then
147
+
148
+ require 'perception'
149
+ rawlog "\n----------------------------------------------------------\n\n"
150
+
151
+ rawlog 'TR_DOWNCASE_ONLY= '
152
+ rawlog TR_DOWNCASE_ONLY
153
+ rawlog "\n"
154
+
155
+ rawlog 'TR_FULL= '
156
+ rawlog TR_FULL
157
+ rawlog "\n"
158
+ rawlog 'TR_REDUCED= '
159
+ rawlog TR_REDUCED
160
+ rawlog "\n"
161
+
162
+ rawlog 'TR_UPCASE= '
163
+ rawlog TR_UPCASE
164
+ rawlog "\n"
165
+ rawlog 'TR_DOWNCASE= '
166
+ rawlog TR_DOWNCASE
167
+ rawlog "\n"
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ end
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
@@ -0,0 +1,78 @@
1
+
2
+
3
+
4
+ class String
5
+
6
+
7
+ # ---------------------------------------------------------------------------------------------------------------------------------
8
+ # :section: overlap / diff
9
+ #
10
+
11
+ # Gibt den gemeinsamen Teil zweier Strings aus (von vorne gezählt).
12
+ #
13
+ # Beispiele & Tests siehe TestString#test_overlap
14
+ def overlap(b)
15
+ return '' if b.nil?
16
+ b = b.to_str
17
+ return self if self == b
18
+ return '' if self[0] != b[0]
19
+
20
+ n = [self.size, b.size].min
21
+ (0..n).each { |i| return self[0..i-1] unless self[i] == b[i] }
22
+ end
23
+
24
+
25
+ # Liefert den Unterschied zwischen zwei Strings zurück.
26
+ # Im Zweifelsfall immer den längsten String.
27
+ # Wenn dann immer noch Zweifel, dann self.
28
+ #
29
+ # Beispiele & Tests siehe TestString#test_diff
30
+ def diff(b)
31
+ return self if b.nil?
32
+ b = b.to_str
33
+ return '' if self == b # kein Unterschied
34
+
35
+ a = self
36
+ a,b = b,a if a.size >= b.size # a ist jetzt k�rzer oder gleichlang wie b
37
+ overlap = a.overlap(b)
38
+ return self if overlap == ''
39
+ return b.split(overlap)[1]
40
+ end
41
+
42
+
43
+
44
+ # Liefert zugleich overlap und diff zurück.
45
+ # Symmetrie: Rechnet man overlap + diff, so erhält man immer den längsten der beiden ursprünglichen Strings.
46
+ # Waren beide gleichlang, so erhält man self.
47
+ # overlapdiff braucht genauso viel Zeit wie diff alleine.
48
+ #
49
+ # Beispiele & Tests siehe TestString#test_overlapdiff
50
+ def overlapdiff(b)
51
+ return '', self if b.nil?
52
+ b = b.to_str
53
+ return self,'' if self == b # kein Unterschied
54
+
55
+ a = self
56
+ a,b = b,a if a.size >= b.size # a ist jetzt k�rzer oder gleichlang wie b
57
+ overlap = a.overlap(b)
58
+ return overlap, self if overlap == ''
59
+ return overlap, b.split(overlap)[1]
60
+ end
61
+
62
+
63
+
64
+ end
65
+
66
+
67
+
68
+ class NilClass
69
+ def overlap(*a); ''; end
70
+ def diff(b); b; end
71
+ def overlapdiff(b); ['', b]; end
72
+ end
73
+
74
+
75
+
76
+
77
+
78
+
@@ -0,0 +1,19 @@
1
+
2
+
3
+
4
+ class String
5
+
6
+ # Wörter zählen
7
+ def count_words
8
+ n = 0
9
+ scan(/\b\S+\b/) { n += 1}
10
+ n
11
+ end
12
+
13
+
14
+ end
15
+
16
+
17
+ class NilClass
18
+ def count_words; 0; end
19
+ end
@@ -0,0 +1,43 @@
1
+
2
+ class String
3
+ alias :old_include? :include?
4
+
5
+ # Nimmt jetzt auch ein Array an.
6
+ # Die Array-Elemente werden ODER-verknüpft, d.h.
7
+ # include? ist true, wenn für mindestens eines der Elemente include? true ist.
8
+ # Alle Strings includen '', [] oder nil.
9
+ # Andersherum enthält nil niemals irgendwas (nil.include? => false)
10
+ def include?(input)
11
+ return true if input.nil?
12
+ return true if input.empty?
13
+ if ( input.respond_to?(:each) && !input.kind_of?(String) )
14
+ input.each do |frag|
15
+ return true if include?(frag)
16
+ end
17
+ false
18
+ else
19
+ old_include?(input)
20
+ end
21
+ end # def
22
+ end
23
+
24
+
25
+ class NilClass
26
+ def include?(*a); false; end
27
+ end
28
+
29
+
30
+ # -----------------------------------------------------------------------------------------
31
+ # ausprobieren
32
+ #
33
+ if $0 == __FILE__ then
34
+
35
+ # puts 'hallo'.include?('ll')
36
+ # puts 'hallo'.include?('lh')
37
+ #puts 'hallo'.include?(['gg'])
38
+ #puts 'hallo'.include?(['lh','gg'])
39
+ puts 'hallo'.include?('')
40
+ puts 'hallo'.include?(nil)
41
+ puts nil.include?(nil)
42
+
43
+ end # if
@@ -0,0 +1,84 @@
1
+
2
+ require 'kyanite/nil'
3
+ require 'kyanite/symbol'
4
+
5
+ class String
6
+
7
+ # ---------------------------------------------------------------------------------------------------------------------------------
8
+ # :section: Listen / Datenbank
9
+ #
10
+
11
+
12
+ # Listet Text auf. Beispiele siehe Tests!
13
+ def list_with( elemente, options = {}, &block )
14
+
15
+ options = { :pre => %q{'},
16
+ :post => %q{'},
17
+ :sep => ' OR ',
18
+ :empty => 'FALSE'}.merge(options)
19
+
20
+
21
+ # keine Liste angegeben
22
+ return options[:empty] if elemente.empty?
23
+
24
+
25
+ # einzelnen String oder einzelnes Symbol angegeben -> ohne Separator ausgeben
26
+ if elemente.kind_of?(String) || !elemente.respond_to?(:each_index)
27
+ e = elemente.dup
28
+ e = yield e if block_given?
29
+ return "#{self}#{options[:pre]}#{e}#{options[:post]}"
30
+ end
31
+
32
+
33
+ # Liste hat nur ein Element -> ohne Separator ausgeben
34
+ if elemente.size <= 1
35
+ e = elemente[0].dup
36
+ e = yield e if block_given?
37
+ return "#{self}#{options[:pre]}#{e}#{options[:post]}"
38
+ end
39
+
40
+
41
+ # Liste hat mehrere Elemente
42
+ result = ''
43
+ elemente[0..-2].each do |e|
44
+ # Die vorderen Elemente mit Separator
45
+ e = yield e if block_given?
46
+ result += "#{self}#{options[:pre]}#{e}#{options[:post]}#{options[:sep]}"
47
+ end
48
+ # Letztes Element ohne Separator
49
+ e = elemente[-1].dup
50
+ e = yield elemente[-1] if block_given?
51
+ result += "#{self}#{options[:pre]}#{e}#{options[:post]}"
52
+ result
53
+ end
54
+
55
+
56
+
57
+ # Gibt eine SQL-RegExp zurück, mit der man in Postgres kommaseparierte Listen duchsuchen kann.
58
+ # Anwendung: Model Merkmal, has_many :dienste_req
59
+ #
60
+ def sql_regexp_for_kommaliste
61
+ '[, ]' + self + '[, ]' + '|' + # match mittendrin
62
+ '^' + self + '[, ]' + '|' + # match am Anfang
63
+ '[, ]' + self + '$' + '|' + # match am Ende
64
+ '^' + self + '$' # match von Anfang bis Ende
65
+ end
66
+
67
+
68
+ # macht aus einer MySQL-Enum-Angabe ein Array
69
+ #
70
+ def enum_to_array
71
+ self[5..-2].gsub("'",'').split(',').collect {|i| [i,i] }
72
+ end
73
+
74
+
75
+
76
+ end
77
+
78
+
79
+ class NilClass
80
+ def list_with(*a); nil; end
81
+ def sql_regexp_for_kommaliste; nil; end
82
+ def enum_to_array; nil; end
83
+ end
84
+
@@ -0,0 +1,35 @@
1
+
2
+ class String
3
+
4
+ # Mehrere Patterns mit einer RegExp replacen.
5
+ # Ruby Cookbook Seite 32
6
+ # "between".mgsub([[/ee/, 'AA'], [/e/, 'E']]) # Good code
7
+ # => "bEtwAAn"
8
+ #
9
+ def mgsub(key_value_pairs=[].freeze)
10
+ regexp_fragments = key_value_pairs.collect { |k,v| k }
11
+ gsub(Regexp.union(*regexp_fragments)) do |match|
12
+ key_value_pairs.detect{|k,v| k =~ match}[1]
13
+ end
14
+ end
15
+ # http://oreilly.com/catalog/9780596523695/
16
+ # Ruby Cookbook, by Lucas Carlson and Leonard Richardson
17
+ # Copyright 2006 O'Reilly Media
18
+
19
+ end # class
20
+
21
+
22
+ class NilClass
23
+ def mgsub(*a); nil; end
24
+ end
25
+
26
+
27
+
28
+ # -----------------------------------------------------------------------------------------
29
+ # ausprobieren
30
+ #
31
+ if $0 == __FILE__ then
32
+
33
+ puts "between".mgsub([[/ee/, 'AA'], [/e/, 'E']])
34
+
35
+ end # if