kyanite 0.7.3 → 0.7.4
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/lib/kyanite/array.rb +34 -4
- data/lib/kyanite/string/cast.rb +8 -0
- data/test/array/test_array.rb +9 -3
- data/test/string/test_cast.rb +7 -0
- data/version.rb +1 -1
- metadata +2 -2
data/lib/kyanite/array.rb
CHANGED
@@ -31,6 +31,14 @@ require 'kyanite/symbol' # size
|
|
31
31
|
# [+to_h(arrayed=nil)+] Converts a two-element associative array into a hash.
|
32
32
|
#
|
33
33
|
class Array
|
34
|
+
|
35
|
+
|
36
|
+
# reverse of {String#to_array_of_codepoints}
|
37
|
+
# @return [String]
|
38
|
+
#
|
39
|
+
def to_s_utf8
|
40
|
+
self.pack("U*").encode('utf-8')
|
41
|
+
end
|
34
42
|
|
35
43
|
|
36
44
|
# Cuts the front portion, and returns the rest.
|
@@ -55,9 +63,10 @@ class Array
|
|
55
63
|
|
56
64
|
|
57
65
|
# Rephrases the index of an Array pos / neg / inv.
|
58
|
-
# [:pos]
|
59
|
-
# [:
|
60
|
-
# [:
|
66
|
+
# [:pos] The index is rephrased as a positive integer
|
67
|
+
# [:detect_last] The index is rephrased as a positive integer, but the last index is -1
|
68
|
+
# [:neg] The index is rephrased as a negative integer
|
69
|
+
# [:inv] if it was positive, then it will get negative, and vice versa
|
61
70
|
#
|
62
71
|
# @return [Integer]
|
63
72
|
#
|
@@ -84,7 +93,17 @@ class Array
|
|
84
93
|
(i - size)
|
85
94
|
else # neg bleibt
|
86
95
|
i
|
87
|
-
end
|
96
|
+
end
|
97
|
+
when :detect_last
|
98
|
+
if i >= 0 # pos bleibt eigentlich
|
99
|
+
if (i == size-1)
|
100
|
+
-1 # nur der Letzte wird -1 genannt
|
101
|
+
else
|
102
|
+
i
|
103
|
+
end
|
104
|
+
else # neg >> pos
|
105
|
+
(i + size)
|
106
|
+
end
|
88
107
|
end #case
|
89
108
|
end #def
|
90
109
|
|
@@ -113,7 +132,18 @@ end
|
|
113
132
|
|
114
133
|
|
115
134
|
|
135
|
+
# ---------------------------------------------------------
|
136
|
+
# Ausprobüeren
|
137
|
+
#
|
138
|
+
if $0 == __FILE__
|
116
139
|
|
140
|
+
test = [ :a, :b, :c, :d]
|
141
|
+
0.upto(3) do | i |
|
142
|
+
puts test.rephrase_index(i, :detect_last)
|
143
|
+
end
|
144
|
+
puts
|
145
|
+
|
146
|
+
end
|
117
147
|
|
118
148
|
|
119
149
|
|
data/lib/kyanite/string/cast.rb
CHANGED
@@ -14,6 +14,14 @@ class String
|
|
14
14
|
|
15
15
|
# @!group Cast
|
16
16
|
|
17
|
+
# reverse of {Array#to_s_utf8}
|
18
|
+
# @return [Array]
|
19
|
+
#
|
20
|
+
def to_array_of_codepoints
|
21
|
+
self.codepoints.to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
|
17
25
|
# Converts a string into the most plausible Identifier
|
18
26
|
#
|
19
27
|
# See examples and tests {TestKyaniteStringCast#test_to_identifier here}.
|
data/test/array/test_array.rb
CHANGED
@@ -16,9 +16,10 @@ class TestKyaniteArray < UnitTest
|
|
16
16
|
def test_rephrase_index
|
17
17
|
test = [ :a, :b, :c, :d]
|
18
18
|
0.upto(3) do | i |
|
19
|
-
i_inv =
|
20
|
-
i_neg =
|
21
|
-
i_pos =
|
19
|
+
i_inv = test.rephrase_index(i)
|
20
|
+
i_neg = test.rephrase_index(i, :neg)
|
21
|
+
i_pos = test.rephrase_index(i, :pos)
|
22
|
+
i_last = test.rephrase_index(i, :detect_last)
|
22
23
|
# print "\n#{test[i]} #{i} #{i_inv}"
|
23
24
|
|
24
25
|
assert_not_equal i, i_inv
|
@@ -28,12 +29,14 @@ class TestKyaniteArray < UnitTest
|
|
28
29
|
assert_equal test[i], test[i_inv]
|
29
30
|
assert_equal test[i], test[i_pos]
|
30
31
|
assert_equal test[i], test[i_neg]
|
32
|
+
assert_equal test[i], test[i_last]
|
31
33
|
end # do
|
32
34
|
|
33
35
|
-4.upto(-1) do | i |
|
34
36
|
i_inv = test.rephrase_index(i)
|
35
37
|
i_neg = test.rephrase_index(i, :neg)
|
36
38
|
i_pos = test.rephrase_index(i, :pos)
|
39
|
+
i_last = test.rephrase_index(i, :detect_last)
|
37
40
|
# print "\n#{test[i]} #{i} #{i_inv}"
|
38
41
|
|
39
42
|
assert_not_equal i, i_inv
|
@@ -43,12 +46,14 @@ class TestKyaniteArray < UnitTest
|
|
43
46
|
assert_equal test[i], test[i_inv]
|
44
47
|
assert_equal test[i], test[i_pos]
|
45
48
|
assert_equal test[i], test[i_neg]
|
49
|
+
assert_equal test[i], test[i_last]
|
46
50
|
end # do
|
47
51
|
|
48
52
|
[4, 5, -5, -6].each do |i|
|
49
53
|
i_inv = test.rephrase_index(i)
|
50
54
|
i_neg = test.rephrase_index(i, :neg)
|
51
55
|
i_pos = test.rephrase_index(i, :pos)
|
56
|
+
i_last = test.rephrase_index(i, :detect_last)
|
52
57
|
# print "\nx #{i} #{i_inv}"
|
53
58
|
assert_equal i, i_neg
|
54
59
|
assert_equal i, i_pos
|
@@ -56,6 +61,7 @@ class TestKyaniteArray < UnitTest
|
|
56
61
|
assert_equal test[i], test[i_inv]
|
57
62
|
assert_equal test[i], test[i_pos]
|
58
63
|
assert_equal test[i], test[i_neg]
|
64
|
+
assert_equal test[i], test[i_last]
|
59
65
|
end
|
60
66
|
|
61
67
|
end
|
data/test/string/test_cast.rb
CHANGED
@@ -6,6 +6,7 @@ if $0 == __FILE__
|
|
6
6
|
end
|
7
7
|
require 'drumherum/unit_test'
|
8
8
|
require 'kyanite/string/cast'
|
9
|
+
require 'kyanite/array'
|
9
10
|
|
10
11
|
|
11
12
|
|
@@ -13,6 +14,12 @@ require 'kyanite/string/cast'
|
|
13
14
|
# @!macro string
|
14
15
|
class TestKyaniteStringCast < UnitTest
|
15
16
|
|
17
|
+
def test_to_array_of_codepoints
|
18
|
+
test = "H¿llÛ"
|
19
|
+
assert_equal [72, 191, 108, 108, 219], test.to_array_of_codepoints
|
20
|
+
assert_equal test, [72, 191, 108, 108, 219].to_s_utf8
|
21
|
+
end
|
22
|
+
|
16
23
|
def test_to_nil
|
17
24
|
assert_equal 'e', 'e'.to_nil
|
18
25
|
assert_equal nil, ''.to_nil
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kyanite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: drumherum
|