kyanite 0.6.1 → 0.7.0

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.
Files changed (86) hide show
  1. data/Div +6 -32
  2. data/{History.txt → History.rdoc} +8 -0
  3. data/{License.txt → License.rdoc} +0 -0
  4. data/Manifest.txt +6 -21
  5. data/README.rdoc +44 -0
  6. data/Rakefile.rb +19 -68
  7. data/console.rb +2 -4
  8. data/lib/kyanite.rb +151 -14
  9. data/lib/kyanite/array.rb +127 -4
  10. data/lib/kyanite/basics.rb +3 -7
  11. data/lib/kyanite/dictionary.rb +19 -21
  12. data/lib/kyanite/enumerable/enumerable_enumerables.rb +22 -24
  13. data/lib/kyanite/enumerable/enumerable_numerics.rb +51 -49
  14. data/lib/kyanite/enumerable/enumerable_strings.rb +18 -25
  15. data/lib/kyanite/enumerable/structure.rb +46 -58
  16. data/lib/kyanite/general/callerutils.rb +30 -28
  17. data/lib/kyanite/general/classutils.rb +73 -63
  18. data/lib/kyanite/general/kernel.rb +45 -64
  19. data/lib/kyanite/general/object.rb +22 -46
  20. data/lib/kyanite/general/true_false.rb +33 -27
  21. data/lib/kyanite/general/undoable.rb +12 -16
  22. data/lib/kyanite/hash.rb +63 -58
  23. data/lib/kyanite/numeric.rb +14 -1
  24. data/lib/kyanite/numeric/float.rb +32 -22
  25. data/lib/kyanite/numeric/integer.rb +12 -20
  26. data/lib/kyanite/optimizer.rb +41 -24
  27. data/lib/kyanite/range.rb +42 -22
  28. data/lib/kyanite/set.rb +56 -63
  29. data/lib/kyanite/string.rb +1 -2
  30. data/lib/kyanite/string/cast.rb +61 -37
  31. data/lib/kyanite/string/chars.rb +66 -36
  32. data/lib/kyanite/string/chars_const.rb +4 -3
  33. data/lib/kyanite/string/diff.rb +64 -34
  34. data/lib/kyanite/string/include.rb +16 -9
  35. data/lib/kyanite/string/list.rb +38 -8
  36. data/lib/kyanite/string/misc.rb +64 -0
  37. data/lib/kyanite/string/nested.rb +39 -22
  38. data/lib/kyanite/string/random.rb +117 -47
  39. data/lib/kyanite/string/split.rb +84 -45
  40. data/lib/kyanite/symbol.rb +30 -21
  41. data/lib/kyanite/tree.rb +33 -28
  42. data/test/_start_all.rb +18 -15
  43. data/test/array/test_array.rb +5 -7
  44. data/test/enumerable/test_enumerable_enumerables.rb +11 -15
  45. data/test/enumerable/test_enumerable_numerics.rb +50 -54
  46. data/test/enumerable/test_enumerable_strings.rb +8 -11
  47. data/test/enumerable/test_structure.rb +6 -8
  48. data/test/general/test_classutils.rb +9 -9
  49. data/test/general/test_object.rb +4 -5
  50. data/test/general/test_true_false.rb +4 -5
  51. data/test/numeric/test_numeric_integer.rb +6 -6
  52. data/test/string/test_cast.rb +4 -5
  53. data/test/string/test_chars.rb +6 -7
  54. data/test/string/test_diff.rb +4 -5
  55. data/test/string/test_list.rb +4 -5
  56. data/test/string/test_misc.rb +58 -0
  57. data/test/string/test_nested.rb +4 -5
  58. data/test/string/test_split.rb +10 -5
  59. data/test/test_dictionary.rb +4 -6
  60. data/test/test_hash.rb +5 -7
  61. data/test/test_optimizer.rb +4 -5
  62. data/test/test_range.rb +8 -9
  63. data/test/test_set.rb +7 -7
  64. data/test/test_tree.rb +7 -10
  65. data/version.rb +8 -0
  66. metadata +32 -33
  67. data/README.txt +0 -47
  68. data/lib/kyanite/array/array.rb +0 -140
  69. data/lib/kyanite/array/array2.rb +0 -142
  70. data/lib/kyanite/array/matrix2.rb +0 -120
  71. data/lib/kyanite/hoe.rb +0 -2
  72. data/lib/kyanite/matrix2.rb +0 -2
  73. data/lib/kyanite/numeric/numeric.rb +0 -54
  74. data/lib/kyanite/operation.rb +0 -5
  75. data/lib/kyanite/operation/call_tracker.rb +0 -69
  76. data/lib/kyanite/operation/hoe.rb +0 -12
  77. data/lib/kyanite/operation/rake.rb +0 -298
  78. data/lib/kyanite/operation/regexp.rb +0 -28
  79. data/lib/kyanite/operation/unit_test.rb +0 -50
  80. data/lib/kyanite/rake.rb +0 -2
  81. data/lib/kyanite/smart_load_path.rb +0 -6
  82. data/lib/kyanite/string/div.rb +0 -28
  83. data/lib/kyanite/string/mgsub.rb +0 -43
  84. data/lib/kyanite/unit_test.rb +0 -2
  85. data/test/array/test_matrix2.rb +0 -166
  86. data/test/string/test_mgsub.rb +0 -58
@@ -1,17 +1,22 @@
1
1
  # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
2
8
  class String
3
9
 
4
- # ---------------------------------------------------------------------------------------------------------------------------------
5
- # :section: include
6
- #
7
-
10
+ # @!group Miscellaneous
11
+
12
+ # @private
8
13
  alias :old_include? :include?
9
14
 
10
- # Nimmt jetzt auch ein Array an.
11
- # Die Array-Elemente werden ODER-verknüpft, d.h.
12
- # include? ist true, wenn für mindestens eines der Elemente include? true ist.
13
- # Alle Strings includen '', [] oder nil.
14
- # Andersherum enthält nil niemals irgendwas (nil.include? => false)
15
+ # Now also accepts an Array as input parameter.
16
+ # The array elements are ORed, i.e. +include?+ is true if +old_include?+ is true for at least one element of the array.
17
+ # All strings include +''+, +[]+ or +nil+.
18
+ # +Nil+ does not include anything: +nil.include? => false+
19
+ #
15
20
  def include?(input)
16
21
  return true if input.nil?
17
22
  return true if input.empty?
@@ -35,6 +40,8 @@ if defined? TransparentNil
35
40
  end
36
41
  end
37
42
 
43
+
44
+
38
45
  # -----------------------------------------------------------------------------------------
39
46
  # ausprobieren
40
47
  #
@@ -1,15 +1,28 @@
1
1
  # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
2
8
  require 'transparent_nil'
3
9
  require 'kyanite/symbol'
4
10
 
5
11
  class String
6
12
 
7
- # ---------------------------------------------------------------------------------------------------------------------------------
8
- # :section: List / Database
9
- # See TestKyaniteStringList for tests and examples.
13
+
14
+ # @!group Database-Helper
10
15
 
11
16
 
12
- # Listet Text auf. Beispiele siehe TestKyaniteStringList
17
+ # Generates WHERE clause from {Array}.
18
+ #
19
+ # Example:
20
+ # array = ['Anna','Birte','Charlie']
21
+ # "kisses_from = ".list_with(array)
22
+ # => "kisses_from = 'Anna' OR kisses_from = 'Birte' OR kisses_from = 'Charlie'"
23
+ #
24
+ # See tests and more examples {TestKyaniteStringList here}.
25
+ # @return [String]
13
26
  def list_with( elemente, options = {}, &block )
14
27
 
15
28
  options = { :pre => %q{'},
@@ -54,9 +67,9 @@ class String
54
67
 
55
68
 
56
69
 
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
- #
70
+ # Returns SQL-RegExp for searching in Postgres comma-separated list.
71
+ # @return [String]
72
+ #
60
73
  def sql_regexp_for_kommaliste
61
74
  '[, ]' + self + '[, ]' + '|' + # match mittendrin
62
75
  '^' + self + '[, ]' + '|' + # match am Anfang
@@ -65,7 +78,8 @@ class String
65
78
  end
66
79
 
67
80
 
68
- # macht aus einer MySQL-Enum-Angabe ein Array
81
+ # Converts MySQL-Enum to {Array}.
82
+ # @return [Array]
69
83
  #
70
84
  def enum_to_array
71
85
  self[5..-2].gsub("'",'').split(',').collect {|i| [i,i] }
@@ -83,3 +97,19 @@ if defined? TransparentNil
83
97
  end
84
98
  end
85
99
 
100
+
101
+ # -----------------------------------------------------------------------------------------
102
+ # Ausprobieren
103
+ #
104
+ if $0 == __FILE__ then
105
+
106
+ require 'kyanite/string/chars'
107
+ array = ['Anna','Birte','Charlie']
108
+ puts "kisses_from = ".list_with(array)
109
+
110
+
111
+
112
+
113
+
114
+ end
115
+
@@ -0,0 +1,64 @@
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
8
+
9
+
10
+
11
+ # @!macro string
12
+ class String
13
+
14
+
15
+ # @!group Miscellaneous
16
+
17
+
18
+ # Counts the number of words.
19
+ # @return [Integer] number of words
20
+ def count_words
21
+ n = 0
22
+ scan(/\b\S+\b/) { n += 1}
23
+ n
24
+ end
25
+
26
+
27
+ # String substitution like +gsub+, but replaces multible patterns in one turn. Example:
28
+ # "between".mgsub([[/ee/, 'II'], [/e/, 'E']])
29
+ # => "bEtwIIn"
30
+ # Tests {TestKyaniteStringMisc here}.
31
+ # @return [String]
32
+ def mgsub(search_and_replace_pairs)
33
+ patterns = search_and_replace_pairs.collect { |search, replace| search }
34
+ gsub(Regexp.union(*patterns)) do |match|
35
+ search_and_replace_pairs.detect{ |search, replace| search =~ match}[1]
36
+ end
37
+ end
38
+
39
+
40
+ end
41
+
42
+
43
+ if defined? TransparentNil
44
+ class NilClass
45
+
46
+ # @return 0
47
+ def count_words; 0; end
48
+
49
+ def mgsub(*a); nil; end
50
+
51
+ end
52
+ end
53
+
54
+
55
+
56
+ # -----------------------------------------------------------------------------------------
57
+ # ausprobieren
58
+ #
59
+ if $0 == __FILE__ then
60
+
61
+ puts "between".mgsub([[/ee/, 'II'], [/e/, 'E']])
62
+ puts "between".mgsub([])
63
+
64
+ end # if
@@ -1,21 +1,27 @@
1
1
  # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
2
8
  class String
3
9
 
4
10
  # ---------------------------------------------------------------------------------------------------------------------------------
5
- # :section: Nested
11
+ # @!group Nested
6
12
  # See TestKyaniteStringNested for tests and examples.
7
13
  #
8
14
 
9
15
 
10
- # Gibt die passende gegenteilige Klammer zurück
11
- # '('.anti -> ')'
12
- # '{'.anti -> '}'
13
- # ']'.anti -> '['
14
- # '<hallo>'.anti -> '</hallo>'
15
- # '</hallo>'.anti -> '<hallo>'
16
+ # Returns the matching opposite bracket. Examples:
17
+ # '('.anti -> ')'
18
+ # '{'.anti -> '}'
19
+ # ']'.anti -> '['
20
+ # '<hallo>'.anti -> '</hallo>'
21
+ # '</hallo>'.anti -> '<hallo>'
16
22
  #
17
- # See TestKyaniteStringNested for tests and examples.
18
- #
23
+ # See tests and examples {TestKyaniteStringNested#test_010_anti here}.
24
+ # @return [String] opposite bracket
19
25
  def anti
20
26
  if self.size == 1
21
27
  return self.tr('([{<)]}>',')]}>([{<')
@@ -31,11 +37,12 @@ class String
31
37
 
32
38
 
33
39
 
34
- # Findet das nächste zueinander passende Klammerpaar ab Position start.
35
- # Liefert die Positionen der Klammern als Range.
36
- # Bsp.: 'Hallo(welt)wort'.index_bracket -> 5..10
37
- #
38
- # See TestKyaniteStringNested for tests and examples.
40
+ # Returns the positions of the next bracket pair. Example:
41
+ # 'Hello(welt)wort'.index_bracket -> 5..10
42
+ # See tests and examples {TestKyaniteStringNested#test_020_index_bracket here}.
43
+ # @return [Range] Positions of brackets
44
+ # @param start [Integer] Search from this starting position
45
+ # @param pattern [RegExp, String] Search only this type of bracket
39
46
  #
40
47
  def index_bracket( pattern=nil, start=0, last_found = nil )
41
48
  return nil if self.empty?
@@ -73,10 +80,20 @@ class String
73
80
  end
74
81
 
75
82
 
76
- # Wendet den Block auf eine hierarchisch definierte Auswahl des Strings an.
83
+ # Applies the block to a hierarchically defined substring of the string.
77
84
  #
78
- # See TestKyaniteStringNested for tests and examples.
79
- #
85
+ # See tests and examples {TestKyaniteStringNested#test_030_mask_ungeklammert here}.
86
+ # @return [String]
87
+ # @param options [Hash]
88
+ # @option options [Integer] :level_start
89
+ # @option options [Integer] :level_end
90
+ # @option options [Integer] :level_akt
91
+ # @option options [RegExp, String] :pattern
92
+ # @option options [Boolean] :skip_empty
93
+ # @option options [Boolean] :param_level
94
+ # @option options [Boolean] :with_brackets
95
+ # @param block [Block]
96
+ #
80
97
  def mask( options={}, &block )
81
98
 
82
99
  # vorbereiten
@@ -189,10 +206,10 @@ class String
189
206
  end # def
190
207
 
191
208
 
192
- # Liefert die Verschachtelungstiefe.
193
- #
194
- # See TestKyaniteStringNested for tests and examples.
195
- #
209
+
210
+ # Returns the depth of nesting (number of nesting levels).
211
+ # @return [Integer] Depth of nesting
212
+ # @param pattern [RegExp, String] Search only this type of bracket
196
213
  def nestinglevel(pattern=/[{<(\[]/)
197
214
  result = 0
198
215
  self.mask( :level_start => 0,
@@ -237,7 +254,7 @@ end
237
254
 
238
255
  if $0 == __FILE__
239
256
 
240
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'string', 'test_nested' )
257
+
241
258
 
242
259
  end # if
243
260
 
@@ -1,66 +1,124 @@
1
1
  # ruby encoding: utf-8
2
-
3
- unless defined? STRING_RANDOM_BASIS
4
- string_random_basis = Hash.new
5
- password = [('0'..'9'),('A'..'Z'),('a'..'z')].map {|range| range.to_a}.flatten
6
- string_random_basis[:password] = password
7
-
8
- de_hauf = [ [ 'ß', 3 ],
9
- [ 'ä', 5 ],
10
- [ 'ö', 3 ],
11
- [ 'ü', 8 ],
12
- [ 'a', 51 ],
13
- [ 'b', 19 ],
14
- [ 'c', 30 ],
15
- [ 'd', 51 ],
16
- [ 'e', 174 ],
17
- [ 'f', 17 ],
18
- [ 'g', 30 ],
19
- [ 'h', 48 ],
20
- [ 'i', 76 ],
21
- [ 'j', 3 ],
22
- [ 'k', 12 ],
23
- [ 'l', 34 ],
24
- [ 'm', 25 ],
25
- [ 'n', 98 ],
26
- [ 'o', 23 ],
27
- [ 'p', 8 ],
28
- [ 'q', 1 ],
29
- [ 'r', 70 ],
30
- [ 's', 72 ],
31
- [ 't', 61 ],
32
- [ 'u', 40 ],
33
- [ 'v', 7 ],
34
- [ 'w', 19 ],
35
- [ 'x', 1 ],
36
- [ 'y', 1 ],
37
- [ 'z', 11 ]]
38
- de_array = []
39
- de_hauf.each do | buchstabe, haufigkeit |
40
- de_array += [buchstabe]*haufigkeit
41
- end
42
- string_random_basis[:de] = de_array
43
- STRING_RANDOM_BASIS = string_random_basis
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
44
6
  end
45
7
 
8
+
46
9
  class String
47
10
 
11
+ unless defined? STRING_RANDOM_BASIS
12
+ string_random_basis = Hash.new
13
+
14
+ password = [('0'..'9'),('A'..'Z'),('a'..'z')].map {|range| range.to_a}.flatten
15
+ string_random_basis[:password] = password
16
+
17
+ de_hauf = [ [ 'ß', 3 ],
18
+ [ 'ä', 5 ],
19
+ [ 'ö', 3 ],
20
+ [ 'ü', 8 ],
21
+ [ 'a', 51 ],
22
+ [ 'b', 19 ],
23
+ [ 'c', 30 ],
24
+ [ 'd', 51 ],
25
+ [ 'e', 174 ],
26
+ [ 'f', 17 ],
27
+ [ 'g', 30 ],
28
+ [ 'h', 48 ],
29
+ [ 'i', 76 ],
30
+ [ 'j', 3 ],
31
+ [ 'k', 12 ],
32
+ [ 'l', 34 ],
33
+ [ 'm', 25 ],
34
+ [ 'n', 98 ],
35
+ [ 'o', 23 ],
36
+ [ 'p', 8 ],
37
+ [ 'q', 1 ],
38
+ [ 'r', 70 ],
39
+ [ 's', 72 ],
40
+ [ 't', 61 ],
41
+ [ 'u', 40 ],
42
+ [ 'v', 7 ],
43
+ [ 'w', 19 ],
44
+ [ 'x', 1 ],
45
+ [ 'y', 1 ],
46
+ [ 'z', 11 ]]
47
+ de_array = []
48
+ de_hauf.each do | buchstabe, haufigkeit |
49
+ de_array += [buchstabe]*haufigkeit
50
+ end
51
+ string_random_basis[:de] = de_array
52
+
53
+ en_hauf = [ [ 'a', 51 ],
54
+ [ 'b', 19 ],
55
+ [ 'c', 30 ],
56
+ [ 'd', 51 ],
57
+ [ 'e', 174 ],
58
+ [ 'f', 17 ],
59
+ [ 'g', 30 ],
60
+ [ 'h', 48 ],
61
+ [ 'i', 76 ],
62
+ [ 'j', 3 ],
63
+ [ 'k', 12 ],
64
+ [ 'l', 34 ],
65
+ [ 'm', 25 ],
66
+ [ 'n', 98 ],
67
+ [ 'o', 23 ],
68
+ [ 'p', 8 ],
69
+ [ 'q', 1 ],
70
+ [ 'r', 70 ],
71
+ [ 's', 72 ],
72
+ [ 't', 61 ],
73
+ [ 'u', 40 ],
74
+ [ 'v', 7 ],
75
+ [ 'w', 19 ],
76
+ [ 'x', 1 ],
77
+ [ 'y', 1 ],
78
+ [ 'z', 11 ]]
79
+ en_array = []
80
+ en_hauf.each do | buchstabe, haufigkeit |
81
+ en_array += [buchstabe]*haufigkeit
82
+ end
83
+ string_random_basis[:en] = en_array
84
+
85
+ STRING_RANDOM_BASIS = string_random_basis
86
+ end
87
+
88
+
48
89
  # ---------------------------------------------------------------------------------------------------------------------------------
49
- # :section: Random
90
+ # @!group Random
50
91
  #
51
92
 
52
- # Zufällige Reihenfolge
93
+ # Reorder string in random order. Example:
94
+ # "Random order".shuffle
95
+ # => "oeo rdRdnmar"
96
+ # @return [String]
53
97
  def shuffle(separator=//)
54
98
  split(separator).shuffle.join('')
55
99
  end
56
100
 
57
- # In-place-Variante von shuffle
101
+ # In-place-variant of {#shuffle +shuffle+}.
102
+ # @return [String]
58
103
  def shuffle!(separator=//)
59
104
  self.replace( shuffle(separator) )
60
105
  end
61
106
 
62
-
63
- def String.random( type=:de, size=16)
107
+ # Generates a random string.
108
+ # Example:
109
+ # String.random( :de, 20)
110
+ # => brräbkpßrdirnenshrnh
111
+ #
112
+ # String.random( :en, 20)
113
+ # => euduwmtenohrtnaeewsc
114
+ #
115
+ # String.random( :password, 20)
116
+ # => PzAAGW2ALsbJRnljI6ho
117
+ #
118
+ # @param type [Symbol] Char base with letter frequency of the random string (+:de+, +:en+ or +:password+)
119
+ # @param size [Integer] Length of the random string
120
+ # @return [String] Random string
121
+ def String.random( type=:en, size=16)
64
122
  (0...size).map { STRING_RANDOM_BASIS[type][Kernel.rand(STRING_RANDOM_BASIS[type].size)] }.join
65
123
  end
66
124
 
@@ -72,3 +130,15 @@ if defined? TransparentNil
72
130
  def shuffle!; nil; end
73
131
  end
74
132
  end
133
+
134
+
135
+ # -----------------------------------------------------------------------------------------
136
+ # Ausprobieren
137
+ #
138
+ if $0 == __FILE__ then
139
+
140
+ puts String.random( :password, 20)
141
+
142
+
143
+
144
+ end