kyanite 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/0_rake_test.bat +12 -0
- data/1_rake_install_gem.bat +20 -0
- data/3_rake_deploy.bat +4 -0
- data/4_ruby_script_console.bat +12 -0
- data/Div +23 -0
- data/History.txt +4 -2
- data/License.txt +21 -2
- data/Manifest.txt +46 -29
- data/README.txt +26 -33
- data/Rakefile.rb +6 -6
- data/config/website.yml +2 -0
- data/lib/kyanite.rb +46 -2
- data/lib/kyanite/array/array.rb +15 -14
- data/lib/kyanite/array/array2.rb +1 -1
- data/lib/kyanite/dictionary.rb +17 -2
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +19 -9
- data/lib/kyanite/enumerable/enumerable_numerics.rb +25 -19
- data/lib/kyanite/enumerable/enumerable_strings.rb +14 -6
- data/lib/kyanite/enumerable/structure.rb +45 -29
- data/lib/kyanite/general/callerutils.rb +9 -1
- data/lib/kyanite/general/classutils.rb +59 -78
- data/lib/kyanite/general/kernel.rb +21 -3
- data/lib/kyanite/general/nil.rb +34 -12
- data/lib/kyanite/general/object.rb +25 -3
- data/lib/kyanite/general/true_false.rb +28 -10
- data/lib/kyanite/general/undoable.rb +24 -0
- data/lib/kyanite/hash.rb +43 -28
- data/lib/kyanite/numeric/float.rb +12 -5
- data/lib/kyanite/numeric/integer.rb +16 -9
- data/lib/kyanite/numeric/numeric.rb +19 -11
- data/lib/kyanite/operation/regexp.rb +5 -1
- data/lib/kyanite/optimizer.rb +31 -16
- data/lib/kyanite/range.rb +15 -8
- data/lib/kyanite/set.rb +35 -6
- data/lib/kyanite/string/cast.rb +18 -7
- data/lib/kyanite/string/chars.rb +24 -17
- data/lib/kyanite/string/diff.rb +14 -5
- data/lib/kyanite/string/div.rb +8 -1
- data/lib/kyanite/string/include.rb +13 -5
- data/lib/kyanite/string/list.rb +3 -3
- data/lib/kyanite/string/mgsub.rb +6 -2
- data/lib/kyanite/string/nested.rb +22 -3
- data/lib/kyanite/string/random.rb +4 -0
- data/lib/kyanite/string/split.rb +15 -7
- data/lib/kyanite/symbol.rb +14 -0
- data/lib/kyanite/tree.rb +10 -4
- data/script/console +10 -0
- data/script/console.cmd +1 -0
- data/script/destroy +14 -0
- data/script/destroy.cmd +1 -0
- data/script/generate +14 -0
- data/script/generate.cmd +1 -0
- data/script/txt2html +82 -0
- data/script/txt2html.cmd +1 -0
- data/tasks/deployment.rake +92 -0
- data/tasks/documentation.rake +28 -0
- data/tasks/environment.rake +7 -0
- data/test/array/test_matrix2.rb +1 -0
- data/test/enumerable/test_enumerable_numerics.rb +3 -2
- data/test/general/test_classutils.rb +3 -0
- data/test/general/test_nil.rb +1 -0
- data/test/general/test_object.rb +2 -1
- data/test/general/test_true_false.rb +1 -0
- data/test/numeric/test_numeric_integer.rb +2 -0
- data/test/string/test_cast.rb +4 -0
- data/test/string/test_chars.rb +3 -0
- data/test/string/test_diff.rb +3 -0
- data/test/string/test_list.rb +2 -0
- data/test/string/test_nested.rb +2 -0
- data/test/string/test_split.rb +3 -0
- data/test/test_dictionary.rb +3 -0
- data/test/test_hash.rb +2 -0
- data/test/test_optimizer.rb +14 -14
- data/test/test_range.rb +1 -0
- data/test/test_tree.rb +1 -1
- metadata +48 -31
data/lib/kyanite/array/array2.rb
CHANGED
data/lib/kyanite/dictionary.rb
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
require 'facets/dictionary'
|
3
3
|
require 'kyanite/enumerable' # is_collection?
|
4
4
|
|
5
|
+
|
6
|
+
|
7
|
+
# [ | Kyanite | Object | Array | Set | Enumerable | *Hash* | ] | Hash | *Dictionary* |
|
8
|
+
# ---
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# == *Tools* *For* *Facets* *Dictionary*
|
12
|
+
# [ ] A Dictionary is a ordered Hash.
|
13
|
+
# [ ] Expands {Facets/Dictionary}[http://facets.rubyforge.org/doc/api/more/classes/Dictionary.html].
|
14
|
+
# [ ] See TestKyaniteDictionary for tests and examples.
|
15
|
+
#
|
16
|
+
#
|
5
17
|
class Dictionary
|
6
18
|
|
7
19
|
def fetch_by_index(index)
|
@@ -42,7 +54,6 @@ end
|
|
42
54
|
|
43
55
|
class Hash
|
44
56
|
|
45
|
-
# :section: Cast
|
46
57
|
# TODO: effizienter
|
47
58
|
def to_dictionary
|
48
59
|
result = Dictionary.new
|
@@ -81,8 +92,12 @@ end
|
|
81
92
|
|
82
93
|
|
83
94
|
class NilClass
|
84
|
-
|
95
|
+
|
96
|
+
# Rückgabe: Leeres Dictionary
|
85
97
|
def to_dictionary; Dictionary.new; end
|
98
|
+
|
99
|
+
def fetch_by_index(*a); nil; end
|
100
|
+
|
86
101
|
end
|
87
102
|
|
88
103
|
|
@@ -9,18 +9,22 @@ module Enumerable
|
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
|
-
# Enumerable
|
12
|
+
# [ | Kyanite | Object | Array | Set | *Enumerable* | Hash | ] | Enumerable | EnumerableNumerics | EnumerableStrings | *EnumerableEnumerables* |
|
13
|
+
# ---
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# == *Enumeration* *Of* *Enumerations*
|
17
|
+
# [ ] Für zweidimensionale Enumerables bzw. Aufzählungen von Objekten, die wiederum aufzählbar sind.
|
18
|
+
# [ ] See TestKyaniteEnumerableEnumerables for tests and examples.
|
19
|
+
# [ ] See ArrayOfEnumerables for an Array with modul EnumerableEnumerables included.
|
20
|
+
#
|
13
21
|
#
|
14
|
-
# ==Aufzählungen aufzählbarer Objekte
|
15
|
-
# Für zweidimensionale Enumerables bzw. Aufzählungen von Objekten, die wiederum aufzählbar sind.
|
16
|
-
# Ein ArrayOfEnumerables inkludiert dieses Modul.
|
17
|
-
#
|
18
22
|
module EnumerableEnumerables
|
19
23
|
|
20
24
|
# Macht das Enumerable rechteckig.
|
21
25
|
# Maßgeblich ist die erste Zeile.
|
22
26
|
#
|
23
|
-
# Tests
|
27
|
+
# Tests and examples see TestKyaniteEnumerableEnumerables.
|
24
28
|
def rectangle
|
25
29
|
qsize = self[0].size
|
26
30
|
result = []
|
@@ -39,11 +43,17 @@ module EnumerableEnumerables
|
|
39
43
|
|
40
44
|
end
|
41
45
|
|
42
|
-
|
46
|
+
|
47
|
+
|
48
|
+
# [ | Kyanite | Object | *Array* | Set | Enumerable | Hash | ] | Array | ArrayOfNumerics | ArrayOfStrings | *ArrayOfEnumerables* | Range |
|
49
|
+
# ---
|
50
|
+
#
|
43
51
|
#
|
44
|
-
#
|
52
|
+
# == *Array* *Of* *Enumerations*
|
53
|
+
# [ ] An ArrayOfEnumerables is an Array with modul EnumerableEnumerables included.
|
54
|
+
# [ ] See TestKyaniteEnumerableEnumerables for tests and examples.
|
45
55
|
#
|
46
|
-
class ArrayOfEnumerables < Array
|
56
|
+
class ArrayOfEnumerables < Array
|
47
57
|
include EnumerableEnumerables
|
48
58
|
end
|
49
59
|
|
@@ -1,8 +1,12 @@
|
|
1
1
|
|
2
|
-
# Enumerable
|
2
|
+
# [ | Kyanite | Object | Array | Set | *Enumerable* | Hash | ] | Enumerable | *EnumerableNumerics* | EnumerableStrings | EnumerableEnumerables |
|
3
|
+
# ---
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# == *Enumeration* *Of* *Numerics*
|
7
|
+
# [ ] See TestKyaniteEnumerableNumerics for tests and examples.
|
8
|
+
# [ ] See ArrayOfNumerics for an Array with modul EnumerableNumerics included.
|
3
9
|
#
|
4
|
-
# ==Aufzählungen numerischer Objekte
|
5
|
-
# Ein ArrayOfNumerics inkludiert dieses Modul.
|
6
10
|
#
|
7
11
|
module EnumerableNumerics
|
8
12
|
|
@@ -12,7 +16,7 @@ module EnumerableNumerics
|
|
12
16
|
#
|
13
17
|
|
14
18
|
# Arithmetrischer Mittelwert
|
15
|
-
# Tests
|
19
|
+
# Tests and examples see TestKyaniteEnumerableNumerics.
|
16
20
|
#
|
17
21
|
def mean
|
18
22
|
self.inject(0.0) { |sum, i | sum += i } / self.length.to_f
|
@@ -28,7 +32,7 @@ module EnumerableNumerics
|
|
28
32
|
# Dann wird der harmonische Mittelwert aller positiven Elemente mit dem
|
29
33
|
# harmonische Mittelwert aller negativen Elemente verrechnet (als gewichtetes arithmetisches Mittel).
|
30
34
|
#
|
31
|
-
# Tests
|
35
|
+
# Tests and examples see TestKyaniteEnumerableNumerics.
|
32
36
|
#
|
33
37
|
def mean_harmonic( options={} )
|
34
38
|
return 0 if self.empty?
|
@@ -67,7 +71,7 @@ module EnumerableNumerics
|
|
67
71
|
|
68
72
|
# Geometrischer Mittelwert
|
69
73
|
def mean_geometric
|
70
|
-
self.
|
74
|
+
self.prd ** ( 1.0/self.size )
|
71
75
|
end
|
72
76
|
|
73
77
|
|
@@ -80,7 +84,7 @@ module EnumerableNumerics
|
|
80
84
|
# Summe
|
81
85
|
#
|
82
86
|
# Methode darf nicht sum heißen, kollidiert sonst schnell mit ActiveRecord.
|
83
|
-
# Tests
|
87
|
+
# Tests and examples see TestKyaniteEnumerableNumerics.
|
84
88
|
#
|
85
89
|
def summation
|
86
90
|
self.inject(0.0) { |sum, i | sum += i }
|
@@ -88,17 +92,16 @@ module EnumerableNumerics
|
|
88
92
|
|
89
93
|
|
90
94
|
# Produkt
|
91
|
-
#
|
92
|
-
# Tests
|
95
|
+
# Methode darf nicht product heißen, die gibt es nämlich schon.
|
96
|
+
# Tests and examples see TestKyaniteEnumerableNumerics.
|
93
97
|
#
|
94
|
-
def
|
95
|
-
self.inject(1.0) { |
|
96
|
-
end
|
97
|
-
alias prd product
|
98
|
+
def prd
|
99
|
+
self.inject(1.0) { |p, i | p *= i }
|
100
|
+
end
|
98
101
|
|
99
102
|
|
100
103
|
# Ergebnis entspricht der Parallelschaltung von Widerständen.
|
101
|
-
# Tests
|
104
|
+
# Tests and examples see TestKyaniteEnumerableNumerics.
|
102
105
|
#
|
103
106
|
def parallel
|
104
107
|
mean_harmonic / size
|
@@ -110,11 +113,15 @@ end #class
|
|
110
113
|
|
111
114
|
|
112
115
|
|
113
|
-
# Array
|
116
|
+
# [ | Kyanite | Object | *Array* | Set | Enumerable | Hash | ] | Array | *ArrayOfNumerics* | ArrayOfStrings | ArrayOfEnumerables | Range |
|
117
|
+
# ---
|
118
|
+
#
|
114
119
|
#
|
115
|
-
#
|
120
|
+
# == *Array* *Of* *Numerics*
|
121
|
+
# [ ] An ArrayOfNumerics is an Array with modul EnumerableNumerics included.
|
122
|
+
# [ ] See TestKyaniteEnumerableNumerics for tests and examples.
|
116
123
|
#
|
117
|
-
class ArrayOfNumerics < Array
|
124
|
+
class ArrayOfNumerics < Array
|
118
125
|
include EnumerableNumerics
|
119
126
|
end
|
120
127
|
|
@@ -138,9 +145,8 @@ class NilClass
|
|
138
145
|
def mean_arithmetric; nil; end
|
139
146
|
def mean_geometric; nil; end
|
140
147
|
def mean_harmonic(*a); nil; end
|
141
|
-
def parallel(*a); nil; end
|
148
|
+
def parallel(*a); nil; end
|
142
149
|
def prd; nil; end
|
143
|
-
def product; nil; end
|
144
150
|
def sum; nil; end
|
145
151
|
def summation; nil; end
|
146
152
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
|
2
|
-
# Enumerable
|
2
|
+
# [ | Kyanite | Object | Array | Set | *Enumerable* | Hash | ] | Enumerable | EnumerableNumerics | *EnumerableStrings* | EnumerableEnumerables |
|
3
|
+
# ---
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# == *Enumeration* *Of* *Strings*
|
7
|
+
# [ ] See TestKyaniteEnumerableStrings for tests and examples.
|
8
|
+
# [ ] See ArrayOfStrings for an Array with modul EnumerableStrings included.
|
3
9
|
#
|
4
|
-
# ==Aufzählungen textueller Objekte
|
5
|
-
# Ein ArrayOfStrings inkludiert dieses Modul.
|
6
10
|
#
|
7
11
|
module EnumerableStrings
|
8
12
|
|
@@ -12,7 +16,7 @@ module EnumerableStrings
|
|
12
16
|
# ['lutm', 'lutmi', 'lutmil', 'lutmila', 'lutrika', 'lutrik', 'lutri', 'lutr']
|
13
17
|
# d.h. vorne und hinten wird alles Gleiche weggestrichen.
|
14
18
|
#
|
15
|
-
# Tests
|
19
|
+
# Tests and examples see TestKyaniteEnumerableStrings.
|
16
20
|
#
|
17
21
|
def palindrom_rumpf
|
18
22
|
result = self.dup
|
@@ -32,9 +36,13 @@ end
|
|
32
36
|
|
33
37
|
|
34
38
|
|
35
|
-
# Array
|
39
|
+
# [ | Kyanite | Object | *Array* | Set | Enumerable | Hash | ] | Array | ArrayOfNumerics | *ArrayOfStrings* | ArrayOfEnumerables | Range |
|
40
|
+
# ---
|
41
|
+
#
|
36
42
|
#
|
37
|
-
#
|
43
|
+
# == *Array* *Of* *Strings*
|
44
|
+
# [ ] An ArrayOfstrings is an Array with modul EnumerableStrings included.
|
45
|
+
# [ ] See TestKyaniteEnumerableStrings for tests and examples.
|
38
46
|
#
|
39
47
|
class ArrayOfStrings < Array
|
40
48
|
include EnumerableStrings
|
@@ -1,56 +1,74 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
# is_collection?
|
4
|
-
#
|
2
|
+
|
5
3
|
|
6
4
|
class Object
|
7
5
|
|
8
|
-
# Enthält ein Objekt mehrere Objekte?
|
9
|
-
# String und Range gelten nicht als Collection.
|
10
|
-
#
|
11
|
-
# Tests & Beispiele siehe TestKyaniteEnumerableStructure.
|
6
|
+
# [ ] Enthält ein Objekt mehrere Objekte?
|
7
|
+
# [ ] String und Range gelten nicht als Collection.
|
8
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
12
9
|
def is_collection?; false; end
|
10
|
+
|
13
11
|
end
|
14
12
|
|
15
13
|
|
16
14
|
module Enumerable
|
17
15
|
|
18
|
-
# Enthält ein Objekt mehrere Objekte?
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
16
|
+
# [ ] Enthält ein Objekt mehrere Objekte?
|
17
|
+
# [ ] Rückgabe: true
|
18
|
+
# [ ] String und Range gelten nicht als Collection.
|
19
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
22
20
|
def is_collection?; true; end
|
21
|
+
|
23
22
|
end
|
24
23
|
|
25
24
|
|
26
|
-
class String
|
25
|
+
class String
|
26
|
+
|
27
|
+
# ---------------------------------------------------------------------------------------------------------------------------------
|
28
|
+
# :section: Structure
|
29
|
+
#
|
30
|
+
|
31
|
+
# [ ] Enthält ein Objekt mehrere Objekte?
|
32
|
+
# [ ] Rückgabe: false
|
33
|
+
# [ ] String und Range gelten nicht als Collection.
|
34
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
27
35
|
def is_collection?; false; end
|
36
|
+
|
37
|
+
|
28
38
|
end
|
29
39
|
|
30
40
|
|
31
|
-
class Range
|
41
|
+
class Range
|
42
|
+
|
43
|
+
# [ ] Enthält ein Objekt mehrere Objekte?
|
44
|
+
# [ ] Rückgabe: false
|
45
|
+
# [ ] String und Range gelten nicht als Collection.
|
46
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
32
47
|
def is_collection?; false; end
|
48
|
+
|
33
49
|
end
|
34
50
|
|
35
51
|
|
36
52
|
|
37
53
|
|
38
|
-
#
|
39
|
-
# Distribution
|
40
|
-
#
|
41
54
|
|
42
55
|
|
43
|
-
|
56
|
+
|
57
|
+
# [ | Kyanite | Object | Array | Set | *Enumerable* | Hash | ] | *Enumerable* | EnumerableNumerics | EnumerableStrings | EnumerableEnumerables |
|
58
|
+
# ---
|
59
|
+
#
|
60
|
+
#
|
61
|
+
# == *General* *Enumerations*
|
62
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
44
63
|
#
|
45
|
-
# ==Allgemeine Aufzählungen
|
46
64
|
#
|
47
65
|
module Enumerable
|
48
66
|
|
49
|
-
# Liefert die Verteilung der size
|
50
|
-
# oder die Verteilung der class
|
51
|
-
# oder die Verteilung eines anderen Merkmals der aufgezählten Elemente.
|
52
|
-
#
|
53
|
-
#
|
67
|
+
# [ ] Liefert die Verteilung der size
|
68
|
+
# [ ] oder die Verteilung der class
|
69
|
+
# [ ] oder die Verteilung eines anderen Merkmals der aufgezählten Elemente.
|
70
|
+
# [ ] die Methode gibt es auch als Hash#distribution.
|
71
|
+
# [ ] See TestKyaniteEnumerableStructure for tests and examples.
|
54
72
|
#
|
55
73
|
def distribution( mode = :size)
|
56
74
|
verteilung = Hash.new
|
@@ -68,9 +86,7 @@ module Enumerable
|
|
68
86
|
|
69
87
|
|
70
88
|
|
71
|
-
|
72
|
-
# contentclass
|
73
|
-
#
|
89
|
+
|
74
90
|
|
75
91
|
# Was für Objekte beinhaltet die Collection?
|
76
92
|
# Liefert die Klasse der Contentelemente, oder <tt>Object</tt> wenn es verschiedene sind.
|
@@ -82,7 +98,7 @@ module Enumerable
|
|
82
98
|
# :ignore_nil => true NilClass wird nicht aufgeführt (STANDARD)
|
83
99
|
# :ignore_nil => false NilClass wird mit aufgeführt
|
84
100
|
#
|
85
|
-
#
|
101
|
+
# See TestKyaniteEnumerableStructure for tests and examples.
|
86
102
|
#
|
87
103
|
def contentclass( options={} )
|
88
104
|
precision = options[:precision] || 2
|
@@ -108,7 +124,7 @@ module Enumerable
|
|
108
124
|
return f
|
109
125
|
else
|
110
126
|
result = f.ancestors & l.ancestors
|
111
|
-
#see result - [Object, Kernel, Precision, Perception::NumericI, PP::ObjectMixin,
|
127
|
+
#see result - [Object, Kernel, Precision, Perception::NumericI, PP::ObjectMixin, KKernel]
|
112
128
|
return Numeric if result.include?(Numeric)
|
113
129
|
return Enumerable if result.include?(Enumerable)
|
114
130
|
return Object
|
@@ -131,7 +147,7 @@ module Enumerable
|
|
131
147
|
c[1..-1].each do |e|
|
132
148
|
result = result & e.ancestors
|
133
149
|
end
|
134
|
-
#see result - [Object, Kernel, Precision, Perception::NumericI, PP::ObjectMixin,
|
150
|
+
#see result - [Object, Kernel, Precision, Perception::NumericI, PP::ObjectMixin, KKernel]
|
135
151
|
return Numeric if result.include?(Numeric)
|
136
152
|
return Enumerable if result.include?(Enumerable)
|
137
153
|
return Object
|
@@ -1,7 +1,15 @@
|
|
1
1
|
|
2
2
|
require 'kyanite/string/include'
|
3
3
|
|
4
|
-
|
4
|
+
|
5
|
+
|
6
|
+
# [ | Kyanite | *Object* | Array | Set | Enumerable | Hash | ] | *Object* | String | Symbol | Numeric |
|
7
|
+
# [ ] | Object | KKernel | *CallerUtils* | Undoable | Class |
|
8
|
+
#
|
9
|
+
# ---
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# == *Tools* *for* Kernel#caller
|
5
13
|
#
|
6
14
|
class CallerUtils
|
7
15
|
|
@@ -4,10 +4,14 @@ require 'facets/kernel/singleton_class' # Easy access to an object‘s "spec
|
|
4
4
|
require 'facets/class/descendents' # Methode descendents
|
5
5
|
|
6
6
|
|
7
|
-
#
|
8
|
-
# Class
|
9
|
-
#
|
10
|
-
|
7
|
+
# [ | Kyanite | *Object* | Array | Set | Enumerable | Hash | ] | *Object* | String | Symbol | Numeric |
|
8
|
+
# [ ] | Object | KKernel | CallerUtils | Undoable | *Class* |
|
9
|
+
#
|
10
|
+
# ---
|
11
|
+
#
|
12
|
+
# == *Class* *Utils*
|
13
|
+
# See TestKyaniteClassutils for tests and examples.
|
14
|
+
#
|
11
15
|
class Class
|
12
16
|
|
13
17
|
# Vergleichsoperator: Alphabetisch.
|
@@ -24,15 +28,20 @@ class Class
|
|
24
28
|
return false
|
25
29
|
end
|
26
30
|
|
27
|
-
#
|
31
|
+
# [ ] Die Methode to_class wandelt einen Klassennamen in eine Klasse.
|
32
|
+
# [ ] Die Methode gibt es insbesondere für String und Symbol, siehe String#to_class, Symbol#to_class
|
33
|
+
# [ ] Für Class ist sie einfach transparent, d.h. sie liefert self.
|
34
|
+
# [ ] Tests and examples see TestKyaniteClassutils
|
35
|
+
#
|
28
36
|
def to_class
|
29
37
|
self
|
30
38
|
end
|
31
39
|
|
32
40
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
41
|
+
# [ ] Gegenstück zu to_class:
|
42
|
+
# [ ] Wandelt eine Klasse in einen Klassennamen um, der nur Kleinbuchstaben enthält.
|
43
|
+
# [ ] Siehe String#to_classname, Symbol#to_classname
|
44
|
+
# [ ] Tests and examples see TestKyaniteClassutils
|
36
45
|
#
|
37
46
|
def to_classname
|
38
47
|
self.to_s.demodulize.underscore
|
@@ -43,26 +52,22 @@ end # class
|
|
43
52
|
|
44
53
|
|
45
54
|
|
46
|
-
|
47
|
-
# Symbol
|
48
|
-
#
|
55
|
+
|
49
56
|
|
50
57
|
class Symbol
|
51
58
|
|
52
|
-
# Wandelt
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# Tests und Beispiele siehe TestKyaniteClassutils
|
59
|
+
# [ ] Wandelt ein Symbol in einen Klassennamen, der nur Kleinbuchstaben enthält.
|
60
|
+
# [ ] Siehe String#to_classname
|
61
|
+
# [ ] Tests and examples see TestKyaniteClassutils
|
56
62
|
#
|
57
63
|
def to_classname
|
58
64
|
self.to_s.to_classname
|
59
65
|
end
|
60
66
|
|
61
|
-
# Wandelt einen Klassennamen in eine Klasse.
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# Tests und Beispiele siehe TestKyaniteClassutils
|
67
|
+
# [ ] Wandelt einen Klassennamen in eine Klasse.
|
68
|
+
# [ ] Akzeptiert sowohl CamelCase als auch down_case.
|
69
|
+
# [ ] Die Methode gibt es auch für String und Class.
|
70
|
+
# [ ] Tests and examples see TestKyaniteClassutils
|
66
71
|
#
|
67
72
|
def to_class
|
68
73
|
self.to_s.to_class
|
@@ -74,71 +79,40 @@ end # class
|
|
74
79
|
|
75
80
|
|
76
81
|
|
77
|
-
|
78
|
-
# String
|
79
|
-
#
|
82
|
+
|
80
83
|
|
81
84
|
class String
|
82
85
|
|
83
|
-
#
|
86
|
+
# ---------------------------------------------------------------------------------------------------------------------------------
|
87
|
+
# :section: Class Utils
|
88
|
+
# See TestKyaniteClassutils for tests and examples.
|
89
|
+
#
|
90
|
+
|
91
|
+
|
92
|
+
# Wandelt einen String in einen Klassennamen, der nur Kleinbuchstaben enthält.
|
93
|
+
# 'MeinModul::EineKlasse' => 'eine_klasse'
|
84
94
|
#
|
85
|
-
#
|
95
|
+
# Tests and examples see TestKyaniteClassutils
|
96
|
+
#
|
97
|
+
def to_classname
|
98
|
+
self.demodulize.underscore
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# [ ] Wandelt einen Klassennamen in eine Klasse.
|
104
|
+
# [ ] Akzeptiert sowohl CamelCase als auch down_case.
|
105
|
+
# [ ] Die Methode gibt es auch für Symbol und Class.
|
106
|
+
# [ ] Tests and examples see TestKyaniteClassutils
|
86
107
|
#
|
87
|
-
# Tests und Beispiele siehe TestKyaniteClassutils
|
88
|
-
#
|
89
108
|
def to_class
|
90
109
|
self.camelize.constantize
|
91
110
|
rescue
|
92
111
|
return nil
|
93
112
|
end
|
94
113
|
|
95
|
-
|
96
|
-
# Wandelt einen String in einen Klassennamen.
|
97
|
-
# 'MeinModul::EineKlasse' => eine_klasse
|
98
|
-
#
|
99
|
-
# Tests und Beispiele siehe TestKyaniteClassutils
|
100
|
-
#
|
101
|
-
def to_classname
|
102
|
-
self.demodulize.underscore
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
114
|
|
108
115
|
|
109
|
-
#
|
110
|
-
# String, from ActiveSupport
|
111
|
-
#
|
112
|
-
|
113
|
-
#
|
114
|
-
# ActiveSupport
|
115
|
-
# --------------
|
116
|
-
#
|
117
|
-
# Copyright (c) 2005 David Heinemeier Hansson
|
118
|
-
#
|
119
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
120
|
-
# a copy of this software and associated documentation files (the
|
121
|
-
# "Software"), to deal in the Software without restriction, including
|
122
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
123
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
124
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
125
|
-
# the following conditions:
|
126
|
-
#
|
127
|
-
# The above copyright notice and this permission notice shall be
|
128
|
-
# included in all copies or substantial portions of the Software.
|
129
|
-
#
|
130
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
131
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
132
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
133
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
134
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
135
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
136
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
137
|
-
#++
|
138
|
-
|
139
|
-
|
140
|
-
class String
|
141
|
-
|
142
116
|
|
143
117
|
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
144
118
|
#
|
@@ -147,7 +121,7 @@ class String
|
|
147
121
|
# Examples:
|
148
122
|
# "ActiveRecord".underscore # => "active_record"
|
149
123
|
# "ActiveRecord::Errors".underscore # => active_record/errors
|
150
|
-
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
|
124
|
+
# [ ] From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
151
125
|
#
|
152
126
|
def underscore
|
153
127
|
self.gsub(/::/, '/').
|
@@ -169,7 +143,7 @@ class String
|
|
169
143
|
# "active_record".camelize(:lower) # => "activeRecord"
|
170
144
|
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
171
145
|
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
172
|
-
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
|
146
|
+
# [ ] From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
173
147
|
#
|
174
148
|
def camelize(first_letter_in_uppercase = true)
|
175
149
|
if first_letter_in_uppercase
|
@@ -185,7 +159,7 @@ class String
|
|
185
159
|
# Examples:
|
186
160
|
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
|
187
161
|
# "Inflections".demodulize # => "Inflections"
|
188
|
-
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
|
162
|
+
# [ ] From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
189
163
|
#
|
190
164
|
def demodulize
|
191
165
|
self.gsub(/^.*::/, '')
|
@@ -210,7 +184,7 @@ class String
|
|
210
184
|
#
|
211
185
|
# NameError is raised when the name is not in CamelCase or the constant is
|
212
186
|
# unknown.
|
213
|
-
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson
|
187
|
+
# From ActiveSupport, Copyright (c) 2005 David Heinemeier Hansson. See License.txt.
|
214
188
|
#
|
215
189
|
def constantize
|
216
190
|
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
|
@@ -224,12 +198,19 @@ end # class
|
|
224
198
|
|
225
199
|
|
226
200
|
class NilClass
|
201
|
+
|
202
|
+
# Rückgabe: Leerer String
|
203
|
+
def to_classname; ''; end
|
204
|
+
|
227
205
|
def camelize; nil; end
|
228
206
|
def constantize; nil; end
|
229
207
|
def demodulize; nil; end
|
230
|
-
def to_class; nil; end
|
231
|
-
def to_classname; ''; end
|
208
|
+
def to_class; nil; end
|
232
209
|
def underscore; nil; end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
233
214
|
end
|
234
215
|
|
235
216
|
|