rubyhelper 1.1.3 → 1.2.alpha4
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +14 -9
- data/lib/rubyhelper/array.rb +26 -8
- data/lib/rubyhelper/gem-version.rb +1 -1
- data/lib/rubyhelper/string.rb +43 -11
- data/rubyhelper.gemspec +2 -2
- data/test/test_array.rb +17 -0
- data/test/test_string.rb +60 -34
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05ffe2c5c0a58b713e88bed0da93ef7fa9c70089
|
4
|
+
data.tar.gz: 77d379e1f9aa30492c732b7071c1a7e3f9345ff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ad32b9aeb04d6bc9c24968d0f6d0e35718d05fe3e3f565284a42a57cb9d6d2dd51d064d9230a3e1e41342322d52d08e9d0b5dc9e36f70799df9ddad254c3d8
|
7
|
+
data.tar.gz: b4b17b5381d554c56c4c2d5760ddb0e31554902eacbb93372cfd0cf3d7751579e87da693bc5e32b91d474ef50366b75edcc5d9954b320099fe5b7562996708dd
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
# rubyhelper
|
2
2
|
|
3
|
-
Gem [](http://badge.fury.io/rb/rubyhelper)
|
4
|
-
|
3
|
+
Last Stable Gem [](http://badge.fury.io/rb/rubyhelper)
|
4
|
+
|
5
|
+
- Last release v1.1 => see the branch #master
|
6
|
+
- Last dev v1.2 => see the branch #dev
|
7
|
+
|
8
|
+
You can see the documentation here : http://rubydoc.info/gems/rubyhelper
|
9
|
+
The source code is available here : https://gitlab.com/poulet_a/rubyhelper
|
5
10
|
|
6
|
-
You can see the documentation here : http://rubydoc.info/gems/rubyhelper/
|
7
11
|
|
8
12
|
## How is it works ?
|
9
13
|
See the [wtf] section too know what is exactly this stuff.
|
10
14
|
Too use the gem, install it :
|
11
|
-
```
|
15
|
+
```bash
|
12
16
|
$ gem install rubyhelper # install the last stable version
|
13
17
|
```
|
14
18
|
|
15
19
|
To use it in your ruby project, use
|
16
|
-
```
|
20
|
+
```ruby
|
17
21
|
require 'rubyhelper'
|
18
22
|
```
|
19
23
|
|
24
|
+
|
20
25
|
## Wtf ?
|
21
26
|
This gem is my own creation. It is a compilation of shortcuts, improvement,
|
22
27
|
helpers about the basic classes, String, Array, ... to make your work easier.
|
@@ -56,17 +61,17 @@ is a little messy. Don't look back 1.1 ;)
|
|
56
61
|
|
57
62
|
|
58
63
|
# TODO
|
59
|
-
|
64
|
+
### Benchmark
|
60
65
|
- Hash.except with
|
61
|
-
```
|
66
|
+
```ruby
|
62
67
|
h.delete_if{|k| [:a].include? k}
|
63
68
|
```
|
64
69
|
|
65
|
-
|
70
|
+
### Improve VersionHelper
|
66
71
|
- Add test
|
67
72
|
- Add more documentation
|
68
73
|
|
69
|
-
|
74
|
+
### Improve main tests
|
70
75
|
- Add few tests for untested features
|
71
76
|
- Improve existing tests (mainly on StringHelper)
|
72
77
|
|
data/lib/rubyhelper/array.rb
CHANGED
@@ -23,27 +23,38 @@ module ArrayHelper
|
|
23
23
|
# Do the sum of an array of integer.
|
24
24
|
# if there is not integer, it will do a to_s.to_i of the element to try
|
25
25
|
# find an integer in the element. else, replace by a simple 0
|
26
|
+
# If the argument toadd is no nill, then the self.size firsts elements
|
27
|
+
# will be added to self and returned
|
28
|
+
# examples: [1,2,3].sum([1,1]) => [2,3,3]
|
29
|
+
# examples: [1,2].sum([1,1,1]) => [2,3]
|
26
30
|
#
|
31
|
+
# @param toadd [Array] if not nil, the array will be added
|
27
32
|
# @return [Integer] the sum of each element (converted via .to_s.to_i)
|
28
|
-
|
29
|
-
|
33
|
+
# @return [Array] an array wich contain the sum of a1[i] + a2[i]
|
34
|
+
def sum(toadd=nil)
|
35
|
+
return (self.size > 0) ? (self.map{|e| e.to_s.to_i}.reduce(:+)) : (0) if toadd.nil?
|
36
|
+
raise ArgumentError, 'Argument is not an Array' unless toadd.is_a? Array
|
37
|
+
return self.zip(toadd).map{|pair| pair.map{|e| e.to_s.to_i}.reduce(&:+) }
|
30
38
|
end
|
31
39
|
|
32
|
-
#
|
40
|
+
# like {#sum} by with a to_f instead of to_i
|
33
41
|
#
|
34
42
|
# @return [Float] the sum of each element (converted via .to_s.to_f)
|
35
|
-
|
36
|
-
|
43
|
+
# @return [Array] an array wich contain the sum of a1[i] + a2[i]
|
44
|
+
def sumf(toadd=nil)
|
45
|
+
return (self.size > 0) ? (self.map{|e| e.to_s.to_f}.reduce(:+)) : (0.0) if toadd.nil?
|
46
|
+
raise ArgumentError, 'Argument is not an Array' unless toadd.is_a? Array
|
47
|
+
return self.zip(toadd).map{|pair| pair.map{|e| e.to_s.to_f}.reduce(&:+) }
|
37
48
|
end
|
38
49
|
|
39
|
-
# Use the sum and divide by the size of the array.
|
50
|
+
# Use the {#sum} and divide by the size of the array.
|
40
51
|
#
|
41
52
|
# @return [Integer] self.sum / self.size. 0 if no elements
|
42
53
|
def average
|
43
54
|
return (self.size > 0) ? (self.sum / self.size) : (0)
|
44
55
|
end
|
45
56
|
|
46
|
-
# Same than average but use to_f instead of to_i
|
57
|
+
# Same than {#average} but use to_f instead of to_i
|
47
58
|
#
|
48
59
|
# @return [Float] self.sumf / self.size. 0.0 if no elements
|
49
60
|
def averagef
|
@@ -75,7 +86,7 @@ module ArrayHelper
|
|
75
86
|
return Array(self.sort[0..(n-1)])
|
76
87
|
end
|
77
88
|
|
78
|
-
#
|
89
|
+
# Same as {#compact} but remove empty string too
|
79
90
|
# see #compact
|
80
91
|
#
|
81
92
|
# @return [Array] compacted array
|
@@ -90,6 +101,13 @@ module ArrayHelper
|
|
90
101
|
return self.replace(self.compacti)
|
91
102
|
end
|
92
103
|
|
104
|
+
# [:a, :b, :c, 1, 2, 3] => [[:a, 1], [:b, 2], [:c, 3]]
|
105
|
+
# [:a, :b, :c, :d, 1, 2, 3] => [[:a, 1], [:b, 2], [:c, 3], [:d, nil]]
|
106
|
+
# [:a, :b, :c, 1, 2, 3, 4] => [[:a, 2], [:b, 3], [:c, 4], [1, nil]]
|
107
|
+
def mirror
|
108
|
+
return self[0..(size/2+size%2-1)].zip(self[(size/2+size%2)..-1])
|
109
|
+
end
|
110
|
+
|
93
111
|
end
|
94
112
|
|
95
113
|
class Array
|
data/lib/rubyhelper/string.rb
CHANGED
@@ -5,17 +5,21 @@ require 'digest'
|
|
5
5
|
|
6
6
|
module StringHelper
|
7
7
|
|
8
|
+
# TODO : raise error on invalid utf-8 param replace
|
8
9
|
# Force utf-8 encoding (shortcut ;) ! )
|
9
10
|
#
|
11
|
+
# @raise [ArgumentError] if replace is not a String
|
10
12
|
# @param replace [String] replace invalids chars by other chas
|
11
13
|
# @return [String] utf-8 string
|
12
14
|
def utf8 replace=''
|
15
|
+
raise ArgumentError, 'replace is not a valid char (String)' unless replace.is_a? String
|
13
16
|
return self.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace)
|
14
17
|
end
|
15
18
|
|
16
19
|
# see {#utf8}
|
17
20
|
#
|
18
|
-
# @
|
21
|
+
# @raise [ArgumentError] if replace is not a String (via {#utf8})
|
22
|
+
# @return [String] utf-8 valid string
|
19
23
|
def utf8!
|
20
24
|
return self.replace(self.utf8)
|
21
25
|
end
|
@@ -24,15 +28,17 @@ module StringHelper
|
|
24
28
|
# Remove accents from the string (convert to ASCII chars !)
|
25
29
|
# And then, change the case as first argument if not nil
|
26
30
|
#
|
31
|
+
# @raise [ArgumentError] if replace is not a String (via {#p} and {#utf8})
|
27
32
|
# @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil for no case change
|
28
33
|
# @param replace [String] if a char is not utf8 valid, character will replace it
|
29
|
-
# @return [String] self changed
|
34
|
+
# @return [String] self changed without accents and non-utf-8 chars
|
30
35
|
def to_plain(case_mod = nil, replace='')
|
31
36
|
return self.p(replace).utf8(replace).to_case(case_mod)
|
32
37
|
end
|
33
38
|
|
34
39
|
# see {#to_plain}
|
35
40
|
#
|
41
|
+
# @raise [ArgumentError] if replace is not a String (via {#to_plain})
|
36
42
|
# @return [String]
|
37
43
|
def to_plain!(case_mod = nil, replace='')
|
38
44
|
return self.replace(self.to_plain(case_mod, replace))
|
@@ -41,6 +47,7 @@ module StringHelper
|
|
41
47
|
# Remove accents from the string, and replace it by the same letter in ASCII
|
42
48
|
# Note : it doesn't remove non ASCII characters
|
43
49
|
#
|
50
|
+
# @raise [ArgumentError] if replace is not a String (via {#utf8})
|
44
51
|
# @param replace [String] replace by character default case
|
45
52
|
# @return [String] self cahnged
|
46
53
|
def p(replace='')
|
@@ -54,6 +61,7 @@ module StringHelper
|
|
54
61
|
|
55
62
|
# see {#p}
|
56
63
|
#
|
64
|
+
# @raise [ArgumentError] if replace is not a String (via {#p})
|
57
65
|
# @return [String]
|
58
66
|
def p!(replace='')
|
59
67
|
return self.replace(self.p(replace))
|
@@ -61,8 +69,8 @@ module StringHelper
|
|
61
69
|
|
62
70
|
# permit to do upcase/downcase/capitalize easier with a simple param
|
63
71
|
#
|
64
|
-
# @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil if no case change
|
65
|
-
# @return [String] self changed
|
72
|
+
# @param case_mod [Symbol] :upcase, :capitalize, :classic or :downcase or nil if no case change. The capitalize correspond to {#scapitalize} and classic to {#capitalize}
|
73
|
+
# @return [String] self changed to downcase, upcase, capitalize or classic_capitalize
|
66
74
|
def to_case(case_mod = :downcase)
|
67
75
|
case case_mod
|
68
76
|
when :upcase
|
@@ -70,6 +78,8 @@ module StringHelper
|
|
70
78
|
when :downcase
|
71
79
|
return self.downcase
|
72
80
|
when :capitalize
|
81
|
+
return self.scapitalize
|
82
|
+
when :classic
|
73
83
|
return self.capitalize
|
74
84
|
else
|
75
85
|
return self
|
@@ -85,14 +95,17 @@ module StringHelper
|
|
85
95
|
|
86
96
|
# Return a simple ascii string. Invalid characters will be replaced by "replace" (argument)
|
87
97
|
# Accents are removed first and replaced by the equivalent ASCII letter (example : 'é' => 'e')
|
98
|
+
# no raise error on {#p} because of default doesn't let it happen ;)
|
88
99
|
#
|
100
|
+
# @raise [ArgumentError] if replace is not a String char
|
89
101
|
# @param replace [String] a caracter to replace non-ascii chars
|
90
102
|
# @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil if no case change
|
91
103
|
# @return [String] self changed
|
92
|
-
def to_ascii(replace=
|
104
|
+
def to_ascii(replace='', case_mod = nil)
|
105
|
+
raise ArgumentError, "Argument replace is not a String char" unless replace.is_a? String
|
93
106
|
s = String.new
|
94
107
|
self.p.each_char do |c|
|
95
|
-
s += ((c.ord > 255) ? (replace
|
108
|
+
s += ((c.ord > 255) ? (replace) : (c))
|
96
109
|
end
|
97
110
|
return s.to_case(case_mod)
|
98
111
|
end
|
@@ -117,8 +130,10 @@ module StringHelper
|
|
117
130
|
|
118
131
|
# CRYXOR (one time pad dirt application)
|
119
132
|
#
|
120
|
-
# @
|
133
|
+
# @raise [ArgumentError] if key is not a valid String
|
134
|
+
# @return [String] encrypted mail
|
121
135
|
def ^(k)
|
136
|
+
raise ArgumentError, "The key MUST BE a String" unless key.is_a? String
|
122
137
|
str = ""
|
123
138
|
self.size.times do |i|
|
124
139
|
str << (self[i].ord ^ k[i % k.size].ord).chr
|
@@ -129,7 +144,7 @@ module StringHelper
|
|
129
144
|
# SHA2 shortcuts
|
130
145
|
# see {Digest::SHA2#hexdigest}
|
131
146
|
#
|
132
|
-
# @return [String]
|
147
|
+
# @return [String] the sha2 hash value of self
|
133
148
|
def sha2
|
134
149
|
Digest::SHA2.hexdigest(self)
|
135
150
|
end
|
@@ -144,11 +159,12 @@ module StringHelper
|
|
144
159
|
# Get a str with a static length.
|
145
160
|
# If the str size > n, reduce the str (keep str from the (param place) )
|
146
161
|
# You should check the test files for examples
|
162
|
+
# Note : {#center} {#left} and {#right} do a similar work.
|
147
163
|
#
|
164
|
+
# @raise [ArgumentError] if n in not an integer/char a String
|
148
165
|
# @param n [Integer] number of char
|
149
166
|
# @param char [String] char to replace if the initial str is too short
|
150
167
|
# @param place [Symbol] :begin/:front :end/:back :center/:middle
|
151
|
-
# @raise [ArgumentError] if n in not an integer/char a String
|
152
168
|
# @return [String]
|
153
169
|
def static(n, char=' ', place= :back)
|
154
170
|
raise ArgumentError, 'char is not an Char (String)' unless char.is_a? String
|
@@ -174,14 +190,18 @@ module StringHelper
|
|
174
190
|
end
|
175
191
|
end
|
176
192
|
end
|
193
|
+
|
194
|
+
# @raise [ArgumentError] via {#static}
|
195
|
+
# see {#static}
|
177
196
|
def static!(n, char=' ')
|
178
197
|
return self.replace(self.static(n, char))
|
179
198
|
end
|
180
199
|
|
181
200
|
# Returns true or false if the string if "true" or "false". else nil
|
182
201
|
#
|
183
|
-
# @return [TrueClass]
|
184
|
-
# @return [FalseClass]
|
202
|
+
# @return [TrueClass] on self == "true"
|
203
|
+
# @return [FalseClass] on self == "false"
|
204
|
+
# @return [NilClass] else
|
185
205
|
def to_t
|
186
206
|
case self
|
187
207
|
when "true"
|
@@ -193,6 +213,18 @@ module StringHelper
|
|
193
213
|
end
|
194
214
|
end
|
195
215
|
|
216
|
+
# @return [TrueClass] if self == "true"
|
217
|
+
# @return [FalseClass] else
|
218
|
+
def true?
|
219
|
+
return (self == "true")
|
220
|
+
end
|
221
|
+
|
222
|
+
# @return [TrueClass] on self == "false"
|
223
|
+
# @return [FalseClass] else
|
224
|
+
def false?
|
225
|
+
return (self == "false")
|
226
|
+
end
|
227
|
+
|
196
228
|
# get only the digits and symbols in the string
|
197
229
|
#
|
198
230
|
# @param sign (true/false) if true, keep the - and + signs
|
data/rubyhelper.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'rubyhelper'
|
5
5
|
s.version = RubyHelper::VERSION
|
6
6
|
s.date = Time.now.getgm.to_s.split.first
|
7
|
-
s.summary = "
|
7
|
+
s.summary = "First real release :) 1.1 with fix doc, fix tests, certification, ..."
|
8
8
|
s.description = "A list of utils for the basic Class of ruby."
|
9
9
|
s.authors = [
|
10
10
|
"poulet_a"
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"test/test_string.rb",
|
29
29
|
"test/test_versionhelper.rb",
|
30
30
|
]
|
31
|
-
s.homepage = "https://gitlab.com/
|
31
|
+
s.homepage = "https://gitlab.com/poulet_a/rubyhelper"
|
32
32
|
s.license = "GNU/GPLv3"
|
33
33
|
s.cert_chain = ['certs/poulet_a.pem']
|
34
34
|
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
|
data/test/test_array.rb
CHANGED
@@ -14,10 +14,20 @@ class ArrayHelperTest < Minitest::Test
|
|
14
14
|
assert_equal(0, [].sum)
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_sum_with_array
|
18
|
+
assert_equal([2,3,4], [1,2,3].sum([1,1,1]))
|
19
|
+
assert_equal([2,3,3], [1,2,3].sum([1,1]))
|
20
|
+
assert_equal([2,3], [1,2].sum([1,1,1]))
|
21
|
+
assert_equal([], [].sum([1,1,1]))
|
22
|
+
assert_equal([1,1,1,3,1,5], [1,1,2,2,3,3].sum([0, 0,-1,+1,-2,+2]))
|
23
|
+
end
|
24
|
+
|
17
25
|
def test_sumf
|
18
26
|
assert_equal(12.0, [1,2, 9].sumf)
|
19
27
|
assert_equal(0.1, [0.01, 0.09, -0, -1, 1.1, -0.1].sumf.round(2))
|
20
28
|
assert_equal(0.0, [].sumf)
|
29
|
+
assert_equal([2.0,3.0], [1,2].sumf([1,1,1]))
|
30
|
+
assert_equal([], [].sumf([1,1,1]))
|
21
31
|
end
|
22
32
|
|
23
33
|
def test_average
|
@@ -38,4 +48,11 @@ class ArrayHelperTest < Minitest::Test
|
|
38
48
|
assert_equal([" "], ["", " ", nil].compacti)
|
39
49
|
end
|
40
50
|
|
51
|
+
# + maths : ok
|
52
|
+
def test_mirror
|
53
|
+
assert_equal([[:a, 1], [:b, 2], [:c, 3]], [:a, :b, :c, 1, 2, 3].mirror)
|
54
|
+
assert_equal([[:a, 1], [:b, 2], [:c, 3], [:d, nil]], [:a, :b, :c, :d, 1, 2, 3].mirror)
|
55
|
+
assert_equal([[:a, 2], [:b, 3], [:c, 4], [1, nil]], [:a, :b, :c, 1, 2, 3, 4].mirror)
|
56
|
+
end
|
57
|
+
|
41
58
|
end
|
data/test/test_string.rb
CHANGED
@@ -5,54 +5,60 @@ require_relative '../lib/rubyhelper'
|
|
5
5
|
class StringHelperTest < Minitest::Test
|
6
6
|
|
7
7
|
def test_to_plain
|
8
|
-
assert_equal("bonjour"
|
9
|
-
assert_equal("bonjouré".to_plain, "bonjoure")
|
10
|
-
assert_equal("bonjo\\AAAur"
|
11
|
-
assert_equal("bonjo
|
8
|
+
assert_equal("bonjour", "bonjour".to_plain)
|
9
|
+
assert_equal("bonjoure", "bonjouré".to_plain, "bonjoure")
|
10
|
+
assert_equal("bonjo\\AAAur", "bonjo\\AAAur".to_plain)
|
11
|
+
assert_equal("bonjo", "bonjo€".to_plain)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_p
|
15
|
-
assert_equal("bonjour"
|
16
|
-
assert_equal("
|
17
|
-
assert_equal("bonjo\\AAAur"
|
18
|
-
assert_equal("bonjo€"
|
15
|
+
assert_equal("bonjour", "bonjour".p)
|
16
|
+
assert_equal("bonjoure", "bonjouré".p)
|
17
|
+
assert_equal("bonjo\\AAAur", "bonjo\\AAAur".p)
|
18
|
+
assert_equal("bonjo€", "bonjo€".p)
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
assert_equal("bonjour".to_case(:downcase)
|
23
|
-
assert_equal("
|
24
|
-
|
21
|
+
def test_to_case_downcase
|
22
|
+
assert_equal("bonjour", "bonJoUr".to_case(:downcase))
|
23
|
+
assert_equal("bonjour toi", "bonJoUr tOI".to_case(:downcase))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_case_upcase
|
27
|
+
assert_equal("BONJOUR", "bonJoUr".to_case(:upcase))
|
28
|
+
assert_equal("BONJOUR TOI", "bonJoUr tOI".to_case(:upcase))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_to_case_capitalize
|
32
|
+
assert_equal("Bonjour", "bonJoUr".to_case(:capitalize))
|
33
|
+
assert_equal("Bonjour Toi", "bonJoUr tOI".to_case(:capitalize))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_to_case_classic
|
37
|
+
assert_equal("Bonjour", "bonJoUr".to_case(:classic))
|
38
|
+
assert_equal("Bonjour toi", "bonJoUr tOI".to_case(:classic))
|
25
39
|
end
|
26
40
|
|
27
41
|
def test_to_ascii
|
28
|
-
assert_equal("bonjoure".to_ascii("")
|
29
|
-
assert_equal("bonjouré".to_ascii("")
|
30
|
-
assert_equal("bonjouré".to_ascii(".")
|
31
|
-
assert_equal("bonjour€".to_ascii("")
|
32
|
-
assert_equal("bonjour€".to_ascii(".")
|
42
|
+
assert_equal("bonjoure", "bonjoure".to_ascii(""))
|
43
|
+
assert_equal("bonjoure", "bonjouré".to_ascii(""))
|
44
|
+
assert_equal("bonjoure", "bonjouré".to_ascii("."))
|
45
|
+
assert_equal("bonjour", "bonjour€".to_ascii(""))
|
46
|
+
assert_equal("bonjour.", "bonjour€".to_ascii("."))
|
33
47
|
end
|
34
48
|
|
35
49
|
def test_to_fi
|
36
|
-
assert_equal("bonjour".to_fi
|
37
|
-
assert_equal("bonj1our".to_fi
|
38
|
-
assert_equal("1.1.1".to_fi
|
39
|
-
assert_equal(
|
40
|
-
assert_equal("1,1".to_fi
|
41
|
-
assert_equal(",1,1".to_fi
|
50
|
+
assert_equal(0.0, "bonjour".to_fi)
|
51
|
+
assert_equal(0.0, "bonj1our".to_fi)
|
52
|
+
assert_equal(1.1, "1.1.1".to_fi)
|
53
|
+
assert_equal(1.1, "1.1".to_fi)
|
54
|
+
assert_equal(1.1, "1,1".to_fi)
|
55
|
+
assert_equal(0.1, ",1,1".to_fi)
|
42
56
|
end
|
43
57
|
|
44
58
|
def test_to_ii
|
45
|
-
assert_equal("1 1".to_ii()
|
46
|
-
assert_equal("06.08.68".to_ii(".")
|
47
|
-
assert_equal("06.08.68".to_ii("\. \t\-")
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_to_t
|
51
|
-
assert_equal("true".to_t, true)
|
52
|
-
assert_equal("false".to_t, false)
|
53
|
-
assert_equal("truex".to_t, nil)
|
54
|
-
assert_equal("xfalsex".to_t, nil)
|
55
|
-
assert_equal("".to_t, nil)
|
59
|
+
assert_equal(11, "1 1".to_ii())
|
60
|
+
assert_equal(60868, "06.08.68".to_ii("."))
|
61
|
+
assert_equal(60868, "06.08.68".to_ii("\. \t\-"))
|
56
62
|
end
|
57
63
|
|
58
64
|
def test_static
|
@@ -72,6 +78,26 @@ class StringHelperTest < Minitest::Test
|
|
72
78
|
assert_equal(" bonjour ", "bonjour".static(11, " ", :center))
|
73
79
|
end
|
74
80
|
|
81
|
+
def test_to_t
|
82
|
+
assert_equal(true, "true".to_t)
|
83
|
+
assert_equal(false, "false".to_t)
|
84
|
+
assert_equal(nil, "truex".to_t)
|
85
|
+
assert_equal(nil, "xfalsex".to_t)
|
86
|
+
assert_equal(nil, "".to_t)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_true?
|
90
|
+
assert_equal(true, "true".true?)
|
91
|
+
assert_equal(false, "false".true?)
|
92
|
+
assert_equal(false, "other".true?)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_false?
|
96
|
+
assert_equal(false, "true".false?)
|
97
|
+
assert_equal(true, "false".false?)
|
98
|
+
assert_equal(false, "other".false?)
|
99
|
+
end
|
100
|
+
|
75
101
|
def test_get_int
|
76
102
|
assert_equal("1312".get_int(), "1312")
|
77
103
|
assert_equal("ea -ze 13e12 à nnazdaz d".get_int(), "-1312")
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyhelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.alpha4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- test/test_numeric.rb
|
73
73
|
- test/test_string.rb
|
74
74
|
- test/test_versionhelper.rb
|
75
|
-
homepage: https://gitlab.com/
|
75
|
+
homepage: https://gitlab.com/poulet_a/rubyhelper
|
76
76
|
licenses:
|
77
77
|
- GNU/GPLv3
|
78
78
|
metadata: {}
|
@@ -87,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- - "
|
90
|
+
- - ">"
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
92
|
+
version: 1.3.1
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
95
|
rubygems_version: 2.4.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary:
|
98
|
+
summary: First real release :) 1.1 with fix doc, fix tests, certification, ...
|
99
99
|
test_files: []
|
100
100
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|