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,64 @@
1
+
2
+
3
+ # -----------------------------------------------------------------------------------------
4
+ # Nil -- hier nur Ruby Core-Methoden!
5
+ #
6
+
7
+ class NilClass
8
+
9
+ # Spezielle Rückgaben
10
+
11
+ def <<(element); [element]; end
12
+ def empty?; true; end
13
+ def length; 0; end
14
+ def size; 0; end
15
+ def count(*a); 0; end
16
+ def split(*a); []; end
17
+ def =~(other); false; end
18
+ def include?(*a); false; end # redundante Definition
19
+
20
+ # Rückgabe nil
21
+ def -(other); nil; end
22
+ def +(other); nil; end
23
+ def <(*a); nil; end
24
+ def <=>(*a); nil; end
25
+ def >(*a); nil; end
26
+ def abs; nil; end
27
+ def chop; nil; end
28
+ def clear; nil; end
29
+ def code; nil; end
30
+ def collect(&block); nil; end
31
+ def compact; nil; end
32
+ def downcase; nil; end
33
+ def dup; nil; end
34
+ def each(*a); nil; end
35
+ # def first; nil; end
36
+ def grep(*a); nil; end
37
+ def gsub!(*a); nil; end
38
+ def gsub(*a); nil; end
39
+ def join; nil; end
40
+ # def last; nil; end
41
+ def pop(*a); nil; end
42
+ def push(*a); nil; end
43
+ def split(*a); nil; end
44
+ def strip!(*a); nil; end
45
+ def strip(*a); nil; end
46
+ def sub(*a); nil; end
47
+ def to_i; nil; end
48
+ def to_integer; nil; end
49
+ def to_sym; nil; end
50
+ def uniq!; nil; end
51
+ def uniq; nil; end
52
+ def [](*a); nil; end
53
+ def []=(*a); nil; end
54
+
55
+ end
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
@@ -0,0 +1,86 @@
1
+
2
+ # Multibyte-Unterstützung von ActiveSupport
3
+ $KCODE = 'UTF8'
4
+ require 'active_support'
5
+
6
+ class Object
7
+
8
+ # <tt> false </tt>
9
+ #
10
+ # Test siehe TestTrueFalse#test_blank.
11
+ def blank?
12
+ false
13
+ end
14
+
15
+ # Quelle: Facets http://facets.rubyforge.org/quick/rdoc/core/classes/Kernel.html#M000379
16
+ def respond(sym, *args)
17
+ return nil if not respond_to?(sym)
18
+ send(sym, *args)
19
+ end
20
+
21
+
22
+ def deep_copy
23
+ Marshal.load( Marshal.dump( self ) )
24
+ end
25
+
26
+
27
+ # Ist ein Objekt numerisch?
28
+ #
29
+ # Tests & Beispiele siehe TestObject#test_is_numeric
30
+ def is_numeric?
31
+ Float self
32
+ rescue Exception => e
33
+ false
34
+ end
35
+
36
+
37
+ # <tt> false </tt>
38
+ def empty?
39
+ false
40
+ end
41
+
42
+
43
+
44
+
45
+
46
+ # Liefert nil, wenn die Condition erfüllt ist. Sonst self.
47
+ #
48
+ def to_nil(condition = :empty)
49
+ return nil if self.respond(condition.to_s + '?')
50
+ return self
51
+ end
52
+
53
+
54
+ # Liefert nil, wenn die Condition nicht erfüllt ist. Sonst self.
55
+ #
56
+ def to_nil_unless(condition = :empty)
57
+ return nil unless self.respond(condition.to_s + '?')
58
+ return self
59
+ end
60
+
61
+
62
+ # Findet den Namen einer Ruby-Konstanten anhand seines Wertes.
63
+ # Funktioniert so nicht. Seltsamersweise funktioniert es aber, wenn man den Quelltext dieser Methode direkt ausführt.
64
+ # Verwendet in der Info-Ansicht des Scaffoldings.
65
+ #
66
+ def name_of_constant(wert_der_konstanten)
67
+ Object.constants.find { |c| Object.const_get(c) == wert_der_konstanten}
68
+ end
69
+ end
70
+
71
+
72
+
73
+
74
+ class NilClass
75
+
76
+ def blank?; false; end
77
+ def is_numeric?; false; end
78
+ def to_nil; nil; end
79
+ def to_nil_unless(*a); nil; end
80
+ def name_of_constant(*a); nil; end
81
+ end
82
+
83
+
84
+
85
+
86
+
@@ -0,0 +1,65 @@
1
+
2
+
3
+ class TrueClass
4
+
5
+ # <tt> 1 </tt>
6
+ def to_i; 1; end
7
+
8
+ # <tt> self </tt>
9
+ def strip; self; end
10
+
11
+ # <tt> self </tt>
12
+ def dup; self; end
13
+
14
+ def <=>(other)
15
+ return 1 if ! other
16
+ return 0
17
+ end
18
+
19
+ def blank?; false; end
20
+
21
+
22
+ end # class
23
+
24
+
25
+
26
+
27
+
28
+ class FalseClass
29
+
30
+ # <tt> 0 </tt>
31
+ def to_i; 0; end
32
+
33
+ # <tt> self </tt>
34
+ def strip; self; end
35
+
36
+ # <tt> self </tt>
37
+ def dup; self; end
38
+
39
+ # TestTrueFalse#test_raumschiff_operator
40
+ def <=>(other)
41
+ return -1 if other
42
+ return 0
43
+ end
44
+
45
+
46
+ # umdefiniert!
47
+ #
48
+ # TestTrueFalse#test_blank
49
+ def blank?; self; end
50
+
51
+
52
+
53
+ end
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
@@ -0,0 +1,24 @@
1
+
2
+ module Undoable
3
+
4
+ @@undoable_history = Hash.new
5
+
6
+ def save(method=:dup)
7
+ return if self == @@undoable_history[self.object_id] # nichts zu tun
8
+ @@undoable_history[self.object_id] = self.send(method)
9
+ end
10
+
11
+ def load_and_keep
12
+ @@undoable_history[self.object_id]
13
+ end
14
+
15
+ def load_and_delete
16
+ @@undoable_history.delete(self.object_id)
17
+ end
18
+
19
+ def self.clear
20
+ @@undoable_history.clear
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,170 @@
1
+
2
+ require 'facets/hash/merge' # Methoden reverse_merge, reverse_merge!
3
+ require 'active_support/core_ext/hash/slice' # Slice a hash to include only the given keys.
4
+ require 'kyanite/enumerable' # is_collection?
5
+
6
+ class Hash
7
+ include ActiveSupport::CoreExtensions::Hash::Slice
8
+ end
9
+
10
+ #
11
+ # Aus {Facets/Hash}[http://facets.rubyforge.org/api/core/classes/Hash.html] eingefügt:
12
+ # * *reverse_merge* <tt>(other_hash) </tt> Beispiel: <tt>options.reverse_merge!(:key => default_value)</tt>
13
+ #
14
+ #
15
+ # ==Generelle Anmerkungen zu Hashes
16
+ # * Definiert man in irgendeinem Objekt die Methode <tt>==(other)</tt>, so muss man auch die Methode +hash+ neu definieren!
17
+ # * Rubys +delete+ und +delete_if+ verändern den Hash! Siehe TestHash#test_delete
18
+ #
19
+ #
20
+ class Hash
21
+
22
+
23
+ if RUBY_VERSION < "1.9"
24
+ # Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
25
+ # Create a hash based on the keys and values.
26
+ def hash
27
+ keys.hash + values.hash + (default ? default.hash : 0)
28
+ end
29
+
30
+ # Credit: Paul Murur http://mucur.name/posts/when-is-a-set-not-a-set
31
+ # To determine whether two hashes are the same, compare
32
+ # their hashes.
33
+ def eql?(other)
34
+ hash == other.hash
35
+ end
36
+ end # Ruby Version
37
+
38
+
39
+
40
+ # Entfernt alle Key-Value-Paare mit <b>nil-Keys</b> in-place.
41
+ #
42
+ # Tests: TestHash#test_delete
43
+ def compact_keys!
44
+ delete_if {|key, value| key.nil? }
45
+ end
46
+
47
+
48
+ # Entfernt alle alle Key-Value-Paare mit <b>nil-Values</b> in-place.
49
+ #
50
+ # Tests: TestHash#test_compact
51
+ def compact_values!
52
+ delete_if {|key, value| value.nil? }
53
+ end
54
+
55
+
56
+ # Entfernt das Key-Value-Paar mit einem bestimmten Key in-place.
57
+ # Rückgabe ist der modifizierte Hash (im Gegensatz zur +delete+-Methode, die das entfernte Key-Value-Paar zurückgibt! ).
58
+ def delete_key(key)
59
+ delete_if { |k,v| k == key }
60
+ end
61
+
62
+ # Entfernt alle Key-Value-Paare mit einem bestimmten Value in-place.
63
+ #
64
+ def delete_value(value)
65
+ delete_if { |k,v| v == value }
66
+ end
67
+
68
+
69
+ # erzwingt ein Array der Länge 1, wenn sowohl Einzelwerte als auch Arrays erlaubt sind.
70
+ # Beispiel:<tt> inputoptions = options.arrayize(:skip, :debug) </tt>
71
+ #
72
+ def arrayize(*keys)
73
+ keys.each do |k|
74
+ if self[k] && !self[k].respond_to?(:first)
75
+ self[k] = [self[k]]
76
+ end
77
+ end
78
+
79
+ self
80
+ end
81
+
82
+
83
+ # Greift auf den Hash mit nicht-ganz-passenden Schlüsseln zu
84
+ def fuzzyget(key, level = 3)
85
+ try = self[key]
86
+ return try if try || level <= 0
87
+ try = self[key.to_s.downcase2]
88
+ return try if try || level <= 1
89
+ try = self[key.to_s.mysqlize]
90
+ return try if try || level <= 2
91
+ end
92
+
93
+
94
+ # Liefert die Verteilung der Size / Class / etc. aller Values.
95
+ # Die Keys werden ignoriert.
96
+ #
97
+ def distribution( mode = :size)
98
+ verteilung = Hash.new
99
+ each do | key, element |
100
+ value = element.respond(mode)
101
+ if verteilung.has_key?(value)
102
+ verteilung[value] += 1
103
+ else
104
+ verteilung[value] = 1
105
+ end # if
106
+ end #each
107
+ verteilung.to_a.sort
108
+ end
109
+
110
+
111
+ # liefert irgendein Value
112
+ def first
113
+ self.each do |key, value|
114
+ return value
115
+ end
116
+ end #def
117
+
118
+
119
+ # liefert irgendein anderes Value
120
+ def last
121
+ first = nil
122
+ self.each do |key, value|
123
+ if first.nil?
124
+ first = value
125
+ next
126
+ else
127
+ return value
128
+ end #if
129
+ end #do
130
+ end #def
131
+
132
+
133
+
134
+
135
+
136
+ end #class
137
+
138
+
139
+ class NilClass
140
+ def compact_keys!; nil; end
141
+ def compact_values!; nil; end
142
+ def delete_key(*a); nil; end
143
+ def delete_value(*a); nil; end
144
+ def arrayize(*a); nil; end
145
+ def fuzzyget(*a); nil; end
146
+ end
147
+
148
+
149
+
150
+
151
+ # ---------------------------------------------------------
152
+ # Ausprobieren
153
+ #
154
+ if $0 == __FILE__
155
+
156
+ require 'perception'
157
+ test = {:b => 2, :a => 1, :c => 3}
158
+ see test.first
159
+ see test.last
160
+
161
+
162
+
163
+
164
+ end
165
+
166
+
167
+
168
+
169
+
170
+
@@ -0,0 +1,2 @@
1
+
2
+ require 'kyanite/array/matrix2'
@@ -0,0 +1,3 @@
1
+
2
+ require 'kyanite/general/nil'
3
+
@@ -0,0 +1,4 @@
1
+
2
+ require 'kyanite/numeric/float'
3
+ require 'kyanite/numeric/integer'
4
+ require 'kyanite/numeric/numeric'
@@ -0,0 +1,26 @@
1
+
2
+ Infinity = 1.0/0 unless defined? Infinity
3
+ Googol = 10**100 unless defined? Googol
4
+
5
+
6
+ class Float
7
+
8
+ # 1.9 == 1.8 + 0.1 => false
9
+ # 1.9.approx(1.8 + 0.1) => true
10
+ # 98.6.approx(98.66) => false
11
+ # 98.6.approx(98.66, 0.001) => true
12
+ # Copyright 2006 O'Reilly Media, Ruby Cookbook, by Lucas Carlson and Leonard Richardson
13
+ #
14
+ def approx(other, relative_epsilon=Float::EPSILON, epsilon=Float::EPSILON)
15
+ difference = other - self
16
+ return true if difference.abs <= epsilon
17
+ relative_error = (difference / (self > other ? self : other)).abs
18
+ return relative_error <= relative_epsilon
19
+ end
20
+ # http://oreilly.com/catalog/9780596523695/
21
+ # Ruby Cookbook, by Lucas Carlson and Leonard Richardson
22
+ # Copyright 2006 O'Reilly Media
23
+
24
+
25
+
26
+ end