kyanite 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,4 +1,10 @@
1
- # ruby encoding: utf-8
1
+ # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
2
8
 
3
9
  require 'facets/string/shatter'
4
10
  require 'kyanite/string/cast'
@@ -10,15 +16,11 @@
10
16
  class String
11
17
 
12
18
  # ---------------------------------------------------------------------------------------------------------------------------------
13
- # :section: Split
19
+ # @!group Split
14
20
  # See TestKyaniteStringSplit for tests and examples.
15
- #
16
- # Aus {Facets/String}[http://facets.rubyforge.org/doc/api/core/classes/String.html]eingefügt:
17
- # *shatter*(re)
18
- # Breaks a string up into an array based on a regular expression. Similar to +scan+, but includes the matches.
21
+
19
22
 
20
23
 
21
-
22
24
  # Returns _n_ characters of the string. If _n_ is positive
23
25
  # the characters are from the beginning of the string.
24
26
  # If _n_ is negative from the end of the string.
@@ -26,11 +28,14 @@ class String
26
28
  # Alternatively a replacement string can be given, which will
27
29
  # replace the _n_ characters.
28
30
  # Example:
31
+ # 'abcde'.nchar(1) => 'a'
29
32
  # 'abcde'.nchar(2) => 'ab'
33
+ # 'abcde'.nchar(3) => 'abc'
30
34
  # 'abcde'.nchar(2,'') => 'cde'
31
35
  #
32
- # NICHT die Version aus Facets verwenden!!!
33
- # Tests siehe TestKyaniteStringSplit#test_nchar
36
+ # (The originaly version of this method is from the {http://rubyworks.github.com/rubyfaux/?doc=http://rubyworks.github.com/facets/docs/facets-2.9.3/core.json#api-class-String/api-method-String-h-nchar Facets} library).
37
+ # See tests and examples {TestKyaniteStringSplit#test_nchar here}.
38
+ # @return [String] Substring
34
39
  def nchar(n, replacement=nil)
35
40
  if replacement
36
41
  return self if n == 0
@@ -48,19 +53,21 @@ class String
48
53
  end
49
54
 
50
55
 
51
- # Schneidet eine String auf eine Maximallänge. Bsp.:
52
- # 'Hallo'.cut(3) => 'Hal'
53
- #
54
- # Tests siehe TestKyaniteStringSplit#test_cut
56
+ # Cuts a string to a maximal length. Example.:
57
+ # 'Hello'.cut(3) => 'Hel'
58
+ #
59
+ # See tests and examples {TestKyaniteStringSplit#test_cut here}.
60
+ # @return [String] Substring
55
61
  def cut(len=5)
56
62
  return '' if len <= 0
57
63
  self[0..len-1]
58
64
  end
59
65
 
60
66
 
61
- # Erzwingt eine bestimmte Länge
62
- #
63
- # Tests siehe TestKyaniteStringSplit#test_fixsize
67
+ # Forces a fixed size.
68
+ #
69
+ # See tests and examples {TestKyaniteStringSplit#test_fixsize here}.
70
+ # @return [String]
64
71
  def fixsize( len )
65
72
  return '' if len <= 0
66
73
  if self.size < len
@@ -71,11 +78,10 @@ class String
71
78
  end
72
79
 
73
80
 
74
- # Schneidet einen String in Stücke.
75
- # Wie lang die Stücke sind, sagt der Parameter (Format: einzelner Integer oder Array of Integer).
76
- # Gibt alle Stücke zurück plus den Rest, der übrigbleibt.
77
- #
78
- # Beispiele & Tests siehe TestKyaniteStringSplit#test_split_by_index
81
+ # Cuts a string in parts with given length.
82
+ # See tests and examples {TestKyaniteStringSplit#test_split_by_index here}.
83
+ # @param idx [Integer, Array of Integer] Length of parts
84
+ # @return [Array] All the parts with given length, plus remainder.
79
85
  def split_by_index(idx)
80
86
  if idx.kind_of?(Integer)
81
87
  [nchar(idx)] + [nchar(idx,'')]
@@ -88,10 +94,14 @@ class String
88
94
 
89
95
 
90
96
 
91
- # Extrahiert einen Teilstring anhand zweier regulärer Ausdrücke. Beispiel:
92
- # string = '<select id="hallo"><option value="0">none</option></select>'
93
- # string.extract(/select.*?id="/,'"') => 'hallo'
94
- #
97
+ # Extracts a substring using two regular expressions. Example:
98
+ # string = '<select id="hello"><option value="0">none</option></select>'
99
+ # string.extract( /select.*?id="/ , '"' ) => 'hello'
100
+ #
101
+ # See tests and examples {TestKyaniteStringSplit#test_extract here}.
102
+ # @return [String] Substring
103
+ # @param start_regexp [RegExp, String] Start extraction here
104
+ # @param stop_regexp [RegExp, String] Stop extraction here
95
105
  def extract( start_regexp, stop_regexp )
96
106
  split(start_regexp)[1].split(stop_regexp)[0]
97
107
  end
@@ -99,18 +109,20 @@ class String
99
109
 
100
110
 
101
111
 
102
- # Trennt einen String in numerische und alphanumerische Teile auf.
103
- # Funktioniert derzeit nur mit positiven Integers. Bsp.:
112
+ # Separates a string into numeric and alphanumeric parts.
113
+ # Currently works only with positive integers. Example:
104
114
  # 'abc123'.split_numeric >> ['abc',123] (Array)
105
115
  # '123abc'.split_numeric >> [123,'abc'] (Array)
106
116
  # '123'.split_numeric >> 123 (Integer)
107
117
  # 'abc'.split_numeric >> 'abc' (String)
108
118
  #
109
- # Das funktioniert sogar mit mehr als zwei Teilen:
119
+ # It even works with more than two parts:
110
120
  # '123abc456'.split_numeric >> [123,'abc',456]
111
121
  # 'abc123def'.split_numeric >> ['abc',123,'def']
122
+ #
123
+ # See tests and examples {TestKyaniteStringSplit#test_split_numeric here}.
124
+ # @return [Array] alphanumeric and numeric part
112
125
  #
113
- # Tests siehe TestKyaniteStringSplit#test_split_numeric
114
126
  def split_numeric
115
127
  result = shatter(/\d+/).collect{ |i| i.to_integer_optional }
116
128
  return result[0] if ( result.is_collection? && result.size == 1 )
@@ -118,28 +130,55 @@ class String
118
130
  end
119
131
 
120
132
 
121
- # Trennt numerische Teile ab und entfernt abschließende Whitespaces, Bindestriche, Unterstriche und Punkte.
122
- # Wird z.B. für die Generierung des Doku-Pfades verwendet.
123
- #
124
- # Tests siehe TestKyaniteStringSplit
133
+
134
+ # Removes numeric parts and trailing white spaces, hyphens, underscores, and periods.
135
+ # See tests and examples {TestKyaniteStringSplit#test_without_versioninfo here}.
136
+ # @return [String] Substring
125
137
  def without_versioninfo
126
138
  shatter(/\d+/)[0].strip.chomp('_').chomp('-').chomp('.')
127
139
  end
128
140
 
129
141
  end
130
142
 
143
+ # @!endgroup
131
144
 
132
- if defined? TransparentNil
133
- class NilClass
145
+ class NilClass
134
146
 
135
- # Rückgabe: Leerer String,
136
- # siehe String#split
137
- def cut(*a); ''; end
138
-
139
- def nchar(*a); nil; end
140
- def split_by_index(*a); nil; end
141
- def extract(*a); nil; end
142
- def split_numeric; nil; end
143
- def without_versioninfo; nil; end
144
- end
147
+ # Rückgabe: Leerer String,
148
+ # siehe String#split
149
+ def cut(*a); ''; end
150
+
151
+ def nchar(*a); nil; end
152
+ def split_by_index(*a); nil; end
153
+ def extract(*a); nil; end
154
+ def split_numeric; nil; end
155
+ def without_versioninfo; nil; end
145
156
  end
157
+
158
+
159
+
160
+ class Numeric
161
+
162
+
163
+ # +self+, complements {String#split_numeric}.
164
+ # @return [Numeric]
165
+ def split_numeric
166
+ self
167
+ end
168
+
169
+
170
+
171
+ end
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
@@ -1,33 +1,42 @@
1
1
  # ruby encoding: utf-8
2
+ # ü
3
+ if $0 == __FILE__
4
+ require 'drumherum'
5
+ smart_init
6
+ end
7
+
8
+
2
9
 
3
- # [ | Kyanite | *Object* | Array | Set | Enumerable | Hash | ] | Object | String | *Symbol* | Numeric |
4
- #
5
- # ---
6
- #
7
- # == *Symbol*
8
- #
9
- #
10
10
  class Symbol
11
-
12
- # Rückgabe: false
13
- def empty?; false; end
11
+
12
+ # @!group Core Extensions
13
+
14
+ # false
15
+ # @return false
16
+ #def empty?; false; end
14
17
 
15
- # Rückgabe: self
18
+ # +self+, you can not dup Symbols
19
+ # @return [self]
16
20
  def dup; self; end
17
21
 
18
- # wie gleichlautende String-Funktion
22
+ # like String method with same name
23
+ # @return [Symbol]
19
24
  def +(other)
20
25
  (self.to_s + other.to_s).to_sym
21
26
  end
22
27
 
23
- # wie gleichlautende String-Funktion
24
- def <=>(other)
25
- self.to_s <=> other.to_s
26
- end
28
+ # like String method with same name
29
+ # @return [Boolean]
30
+ # def <=>(other)
31
+ # self.to_s <=> other.to_s
32
+ # end
27
33
 
28
- # wie gleichlautende String-Funktion
29
- def size
30
- self.to_s.size
31
- end
34
+ # like String method with same name
35
+ # @return [Integer]
36
+ # def size
37
+ # self.to_s.size
38
+ # end
32
39
 
33
- end
40
+ end
41
+
42
+
data/lib/kyanite/tree.rb CHANGED
@@ -1,27 +1,29 @@
1
1
  # ruby encoding: utf-8
2
2
  if $0 == __FILE__
3
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'smart_load_path.rb' )
4
- smart_load_path
3
+ require 'drumherum'
4
+ smart_init
5
5
  end
6
6
 
7
7
  require 'rubytree'
8
- require 'transparent_nil'
8
+ require 'transparent_nil' unless defined? TransparentNil
9
9
 
10
10
 
11
- module Tree #:nodoc:
11
+ module Tree
12
12
 
13
- # [ | *Kyanite* | Object | Array | Set | Enumerable | Hash | ] | Kyanite | TrueClass | FalseClass | NilClass | *Div* |
14
- # [ ] | Div | <b>Tree::TreeNode</b> | Optimizer |
15
- # ---
16
- #
17
- # == Ergänzungen zu rubytree
18
- # See TestKyaniteTree for tests and examples.
19
- #
13
+
14
+
15
+
16
+
17
+ # @!macro tree
20
18
  class TreeNode
21
- attr_reader :childrenHash
19
+
20
+ # @private
21
+ attr_reader :children_hash
22
22
 
23
+ # @!group Additions for rubytree
23
24
 
24
- # kann jetzt auch mit Symbolen umgehen
25
+ # now handles symbols in the tree as well
26
+ # @return [String]
25
27
  def to_s
26
28
  ":#{@name}"
27
29
  # "Node Name: #{@name}" +
@@ -32,7 +34,8 @@ module Tree #:nodoc:
32
34
  end
33
35
 
34
36
 
35
- # funktioniert jetzt
37
+ # now it works
38
+ # @return [void]
36
39
  def print_tree(level = 0, breite = 8)
37
40
 
38
41
  if is_root?
@@ -56,8 +59,8 @@ module Tree #:nodoc:
56
59
  end
57
60
 
58
61
 
59
- # anders als [] wird der gesamte Baum durchsucht
60
- # Liefert den ersten Treffer
62
+ # As opposed to [] the entire tree is searched.
63
+ # Returns the first hit.
61
64
  def find( node_name )
62
65
  return self if self.name == node_name
63
66
  result = self[node_name]
@@ -72,18 +75,20 @@ module Tree #:nodoc:
72
75
  end
73
76
 
74
77
 
75
- # Funktioniert nicht
76
- # Liefert ein Array aller untergeordneten Child-Keys.
77
- # Es wird der gesamte Baum durchsucht.
78
- # def all_child_keys
79
- # result = @childrenHash.keys || []
80
- # children do |c|
81
- # puts "durchsuche #{c}"
82
- # next if c.childrenHash.empty?
83
- # result += c.all_child_keys
84
- # end
85
- # result
86
- # end
78
+
79
+ # Returns an array of all child keys.
80
+ # The whole tree is searched.
81
+ # @return [Array]
82
+ #
83
+ def all_child_keys
84
+ result = @children_hash.keys || []
85
+ children do |c|
86
+ #puts "durchsuche #{c}"
87
+ next if c.children_hash.empty?
88
+ result += c.all_child_keys
89
+ end
90
+ result
91
+ end
87
92
 
88
93
 
89
94
 
data/test/_start_all.rb CHANGED
@@ -1,24 +1,27 @@
1
1
  # ruby encoding: utf-8
2
- #!/usr/bin/env ruby
3
2
  #
4
3
  # Führt alle Tests aus
5
4
  #
6
5
 
7
- if $0 == __FILE__
8
- require File.join(File.dirname(__FILE__), '..', 'smart_load_path.rb' )
9
- smart_load_path
10
- end
6
+ if $0 == __FILE__
7
+ require 'drumherum'
8
+ smart_init
9
+ end
11
10
 
12
- require 'transparent_nil'
11
+ require 'transparent_nil'
13
12
 
14
- # Test-Verzeichnis der Applikation
15
- test_verzeichnis = File.expand_path(File.dirname(__FILE__) )
16
-
17
- Dir["#{test_verzeichnis}/test_*.rb"].sort.each { |t| require t }
18
- Dir["#{test_verzeichnis}/array/test_*.rb"].sort.each { |t| require t }
19
- Dir["#{test_verzeichnis}/enumerable/test_*.rb"].sort.each { |t| require t }
20
- Dir["#{test_verzeichnis}/general/test_*.rb"].sort.each { |t| require t }
21
- Dir["#{test_verzeichnis}/numeric/test_*.rb"].sort.each { |t| require t }
22
- Dir["#{test_verzeichnis}/string/test_*.rb"].sort.each { |t| require t }
13
+
14
+ # Test-Verzeichnisse der Applikation
15
+ Dir["#{File.join(Drumherum::directory_main, 'test')}/test_*.rb"].sort.each { |t| require t }
16
+
17
+ Dir["#{File.join(Drumherum::directory_main, 'test', 'array' )}/test_*.rb"].sort.each { |t| require t }
18
+ Dir["#{File.join(Drumherum::directory_main, 'test', 'enumerable' )}/test_*.rb"].sort.each { |t| require t }
19
+ Dir["#{File.join(Drumherum::directory_main, 'test', 'general' )}/test_*.rb"].sort.each { |t| require t }
20
+ Dir["#{File.join(Drumherum::directory_main, 'test', 'numeric' )}/test_*.rb"].sort.each { |t| require t }
21
+ Dir["#{File.join(Drumherum::directory_main, 'test', 'string' )}/test_*.rb"].sort.each { |t| require t }
22
+
23
+
24
+
25
+
23
26
 
24
27
 
@@ -1,18 +1,16 @@
1
1
  # ruby encoding: utf-8
2
2
  # ü
3
3
  if $0 == __FILE__
4
- require File.join(File.dirname(__FILE__), '..', '..', 'smart_load_path.rb' )
5
- smart_load_path
4
+ require 'drumherum'
5
+ smart_init
6
6
  end
7
-
8
- require 'kyanite/unit_test'
9
- require 'kyanite/array/array'
7
+ require 'drumherum/unit_test'
8
+ require 'kyanite/array'
10
9
  require 'kyanite/numeric/numeric'
11
10
  require 'kyanite/set'
12
11
 
13
12
 
14
- # Tests für Array
15
- #
13
+ # @!macro array
16
14
  class TestKyaniteArray < UnitTest
17
15
 
18
16
  def test_rephrase_index
@@ -1,41 +1,37 @@
1
1
  # ruby encoding: utf-8
2
2
  # ü
3
3
  if $0 == __FILE__
4
- require File.join(File.dirname(__FILE__), '..', '..', 'smart_load_path.rb' )
5
- smart_load_path
4
+ require 'drumherum'
5
+ smart_init
6
+ require 'perception'
6
7
  end
7
-
8
- require 'kyanite/unit_test'
8
+ require 'drumherum/unit_test'
9
9
  require 'kyanite/enumerable/enumerable_enumerables'
10
10
 
11
- class Array
12
- include EnumerableEnumerables
13
- end
14
-
15
11
 
16
- # Tests für EnumerableEnumerables
17
- #
12
+ # @!macro enum_of_enums
18
13
  class TestKyaniteEnumerableEnumerables < UnitTest
19
14
 
20
15
  def test_rectangle1
21
- test = []
16
+ test = ArrayOfEnumerables.new
22
17
  test << [ :a, :b, :c ]
23
18
  test << [ 1, 2, 3 ]
24
19
  test << [ 'i', 'ii', 'iii' ]
20
+
25
21
  assert_equal test, test.rectangle
26
22
  assert_equal test, test.rectangle.rectangle
27
- assert_equal test.transpose, test.rectangle.transpose.rectangle
23
+ assert_equal test.transpose, test.rectangle.transpose.to_array_of_enumerables.rectangle
28
24
  end
29
25
 
30
26
 
31
27
 
32
28
  def test_rectangle2
33
- test = []
29
+ test = ArrayOfEnumerables.new
34
30
  test << [ :a, :b, :c ]
35
31
  test << [ 1, 2, 3, 4 ]
36
32
  test << [ 'i', 'ii' ]
37
33
 
38
- expc = []
34
+ expc = ArrayOfEnumerables.new
39
35
  expc << [ :a, :b, :c ]
40
36
  expc << [ 1, 2, 3 ]
41
37
  expc << [ 'i', 'ii', nil ]
@@ -43,7 +39,7 @@ class TestKyaniteEnumerableEnumerables < UnitTest
43
39
 
44
40
  assert_equal expc, test.rectangle
45
41
  assert_equal expc, test.rectangle.rectangle
46
- assert_equal expc.transpose, test.rectangle.transpose.rectangle
42
+ assert_equal expc.transpose, test.rectangle.transpose.to_array_of_enumerables.rectangle
47
43
  end
48
44
 
49
45
  end # class