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.
- data/Div +6 -32
- data/{History.txt → History.rdoc} +8 -0
- data/{License.txt → License.rdoc} +0 -0
- data/Manifest.txt +6 -21
- data/README.rdoc +44 -0
- data/Rakefile.rb +19 -68
- data/console.rb +2 -4
- data/lib/kyanite.rb +151 -14
- data/lib/kyanite/array.rb +127 -4
- data/lib/kyanite/basics.rb +3 -7
- data/lib/kyanite/dictionary.rb +19 -21
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +22 -24
- data/lib/kyanite/enumerable/enumerable_numerics.rb +51 -49
- data/lib/kyanite/enumerable/enumerable_strings.rb +18 -25
- data/lib/kyanite/enumerable/structure.rb +46 -58
- data/lib/kyanite/general/callerutils.rb +30 -28
- data/lib/kyanite/general/classutils.rb +73 -63
- data/lib/kyanite/general/kernel.rb +45 -64
- data/lib/kyanite/general/object.rb +22 -46
- data/lib/kyanite/general/true_false.rb +33 -27
- data/lib/kyanite/general/undoable.rb +12 -16
- data/lib/kyanite/hash.rb +63 -58
- data/lib/kyanite/numeric.rb +14 -1
- data/lib/kyanite/numeric/float.rb +32 -22
- data/lib/kyanite/numeric/integer.rb +12 -20
- data/lib/kyanite/optimizer.rb +41 -24
- data/lib/kyanite/range.rb +42 -22
- data/lib/kyanite/set.rb +56 -63
- data/lib/kyanite/string.rb +1 -2
- data/lib/kyanite/string/cast.rb +61 -37
- data/lib/kyanite/string/chars.rb +66 -36
- data/lib/kyanite/string/chars_const.rb +4 -3
- data/lib/kyanite/string/diff.rb +64 -34
- data/lib/kyanite/string/include.rb +16 -9
- data/lib/kyanite/string/list.rb +38 -8
- data/lib/kyanite/string/misc.rb +64 -0
- data/lib/kyanite/string/nested.rb +39 -22
- data/lib/kyanite/string/random.rb +117 -47
- data/lib/kyanite/string/split.rb +84 -45
- data/lib/kyanite/symbol.rb +30 -21
- data/lib/kyanite/tree.rb +33 -28
- data/test/_start_all.rb +18 -15
- data/test/array/test_array.rb +5 -7
- data/test/enumerable/test_enumerable_enumerables.rb +11 -15
- data/test/enumerable/test_enumerable_numerics.rb +50 -54
- data/test/enumerable/test_enumerable_strings.rb +8 -11
- data/test/enumerable/test_structure.rb +6 -8
- data/test/general/test_classutils.rb +9 -9
- data/test/general/test_object.rb +4 -5
- data/test/general/test_true_false.rb +4 -5
- data/test/numeric/test_numeric_integer.rb +6 -6
- data/test/string/test_cast.rb +4 -5
- data/test/string/test_chars.rb +6 -7
- data/test/string/test_diff.rb +4 -5
- data/test/string/test_list.rb +4 -5
- data/test/string/test_misc.rb +58 -0
- data/test/string/test_nested.rb +4 -5
- data/test/string/test_split.rb +10 -5
- data/test/test_dictionary.rb +4 -6
- data/test/test_hash.rb +5 -7
- data/test/test_optimizer.rb +4 -5
- data/test/test_range.rb +8 -9
- data/test/test_set.rb +7 -7
- data/test/test_tree.rb +7 -10
- data/version.rb +8 -0
- metadata +32 -33
- data/README.txt +0 -47
- data/lib/kyanite/array/array.rb +0 -140
- data/lib/kyanite/array/array2.rb +0 -142
- data/lib/kyanite/array/matrix2.rb +0 -120
- data/lib/kyanite/hoe.rb +0 -2
- data/lib/kyanite/matrix2.rb +0 -2
- data/lib/kyanite/numeric/numeric.rb +0 -54
- data/lib/kyanite/operation.rb +0 -5
- data/lib/kyanite/operation/call_tracker.rb +0 -69
- data/lib/kyanite/operation/hoe.rb +0 -12
- data/lib/kyanite/operation/rake.rb +0 -298
- data/lib/kyanite/operation/regexp.rb +0 -28
- data/lib/kyanite/operation/unit_test.rb +0 -50
- data/lib/kyanite/rake.rb +0 -2
- data/lib/kyanite/smart_load_path.rb +0 -6
- data/lib/kyanite/string/div.rb +0 -28
- data/lib/kyanite/string/mgsub.rb +0 -43
- data/lib/kyanite/unit_test.rb +0 -2
- data/test/array/test_matrix2.rb +0 -166
- data/test/string/test_mgsub.rb +0 -58
data/lib/kyanite/string/split.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
#
|
33
|
-
#
|
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
|
-
#
|
52
|
-
# '
|
53
|
-
#
|
54
|
-
#
|
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
|
-
#
|
62
|
-
#
|
63
|
-
#
|
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
|
-
#
|
75
|
-
#
|
76
|
-
#
|
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
|
-
#
|
92
|
-
# string = '<select id="
|
93
|
-
# string.extract(/select.*?id="
|
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
|
-
#
|
103
|
-
#
|
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
|
-
#
|
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
|
-
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
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
|
-
|
133
|
-
class NilClass
|
145
|
+
class NilClass
|
134
146
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
+
|
data/lib/kyanite/symbol.rb
CHANGED
@@ -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
|
-
|
13
|
-
|
11
|
+
|
12
|
+
# @!group Core Extensions
|
13
|
+
|
14
|
+
# false
|
15
|
+
# @return false
|
16
|
+
#def empty?; false; end
|
14
17
|
|
15
|
-
#
|
18
|
+
# +self+, you can not dup Symbols
|
19
|
+
# @return [self]
|
16
20
|
def dup; self; end
|
17
21
|
|
18
|
-
#
|
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
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
4
|
-
|
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
|
11
|
+
module Tree
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# See TestKyaniteTree for tests and examples.
|
19
|
-
#
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# @!macro tree
|
20
18
|
class TreeNode
|
21
|
-
|
19
|
+
|
20
|
+
# @private
|
21
|
+
attr_reader :children_hash
|
22
22
|
|
23
|
+
# @!group Additions for rubytree
|
23
24
|
|
24
|
-
#
|
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
|
-
#
|
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
|
-
#
|
60
|
-
#
|
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
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
if $0 == __FILE__
|
7
|
+
require 'drumherum'
|
8
|
+
smart_init
|
9
|
+
end
|
11
10
|
|
12
|
-
|
11
|
+
require 'transparent_nil'
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
|
data/test/array/test_array.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
2
|
# ü
|
3
3
|
if $0 == __FILE__
|
4
|
-
require
|
5
|
-
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
6
|
end
|
7
|
-
|
8
|
-
require 'kyanite/
|
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
|
-
#
|
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
|
5
|
-
|
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
|
-
#
|
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
|