rubyhelper 1.2.3 → 1.3.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f44062bda82f0949141614ec8fb1216b20e1599
4
- data.tar.gz: b4629c6c94bcf2c049adf3b1d24a65ecdce80263
3
+ metadata.gz: a1f4edaf82de992fef8b624d3e60f65bbf3caeba
4
+ data.tar.gz: 5eaab752391cac8972ab6839b1d491ce11f969cc
5
5
  SHA512:
6
- metadata.gz: 6e04829054dda3c8673a88621c11119ab93eca261854cacbadd24541a4422f7978f161e88422a1662217eb18ab2bb52a1f711e09864d5c764fbf3e219dc2d83e
7
- data.tar.gz: f311d972006dd62db14740e9ad53bdb7cc2f206c20886cd867fbb5ed6813fa6bdb9072bf26f3432bf79b67ee68477db1e704406657dcbb5d6c03ecfa490ad53d
6
+ metadata.gz: 4aa6a80fbe1c04dc7d91e14ea103976f6f16b00f65fe1aedfe5057966d7b7ecbb0e1a373377d356272265b17bdffaf8901b3e3bea204640d136ce7ca0f688172
7
+ data.tar.gz: a2663e6dabe5efdf00a81f8b1f00f836b1601877f2ff540ca25bcdea78cb4ede8f71628b7903f3602b5a0fe70a347fcd14ddd1c6c8d9be0e8714b89784d5e726
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -46,36 +46,55 @@ The following sources code is not only my stuff, but also an implementation of
46
46
  idea found on stackoverflow, ...
47
47
 
48
48
  The developpement running like that :
49
- 1. Found idea or a bug
49
+
50
+ ### Development time (dev branch) ###
51
+ 1. Found idea, create a new feature-* branch from branch#dev
50
52
  2. Puts idea or fix it in the source code (*can be switched with 3.*)
51
- 3. Develops few tests and documentation
52
- 4. Push the new code in the dev branch (*and tag it like v1.0.alpha2*)
53
- 5. **repeat 1-4 actions few times**
54
- 6. Improves tests and checks the documentation, hunts the bugs
55
- 7. Validates the version
56
- 8. Push the version into master branch and tag it as stable (*like v1.2*). Publish the gem.
57
- 9. Push new releases if needed (*hotfixs mainly*) (*like v1.2.2*)
58
-
59
- Note about the first time developpement :
53
+ 3. Develops few tests and documente the code (*can be switched with 2.*)
54
+ 4. Merge the new code in the branch#dev with "--no-ff" option (*and optionaly tag it like v1.0.alpha2*)
55
+ 5. Update the Changelog etc.
56
+ 6. **repeat 1-5 actions few times until the next X or Y version**
57
+
58
+ ### Release Time (release branch) ###
59
+ 7. Start a branch#release-X.Y
60
+ 8. Improves tests and checks the documentation, hunts the bugs
61
+ 9. Validates the version
62
+ 10. Push the version into branch#master and tag it as stable (*like v1.2*). Publish the gem.
63
+ 11. Merge with branch#release with branch#dev and got to the next dev version
64
+
65
+ ### Bugfix time (release branch) ###
66
+ 13. Found bug in the code of a release, or an improvement
67
+ 14. Develop the patch in branch#hotfix-*
68
+ 15. Merge with branch#master, branch#dev
69
+ 16. Publish the new release vX.Y.Z if needed
70
+
71
+
72
+ **Note about the first time developpement**
60
73
  I didn't predict to keep this gem in dev so the first part of the dev
61
- is a little messy. Don't look back 1.1 ;)
74
+ is a little messy. Don't look back 1.1 ;)
75
+
62
76
 
77
+ ## Note about the development
78
+ ###Version
79
+ Stable :
80
+ - X : major version, not compatible very with the previous. Lot of changes
81
+ - X.Y : minor version, new features, almost fully compatible with other X.Y
82
+ - X.Y.Z : release improvement, fix bugs, fully compatible with X.Y.Z
63
83
 
64
- # TODO
65
- ### Benchmark
66
- - Hash.except with
67
- ```ruby
68
- h.delete_if{|k| [:a].include? k}
69
- ```
84
+ Development :
85
+ - X.Y-alpha : 1th dev part. Dev new features
86
+ - X.Y-beta : 2sd part. Dev tests, documentation, improvements, fix, few other feats
87
+ - X.Y-rc : last part. Fixs, documentation, and tests only.
70
88
 
71
- ### Improve VersionHelper
72
- - Add test
73
- - Add more documentation
89
+ ### Branchs
90
+ - master : contain the last vX.Y.Z version published (stable)
91
+ - dev : contain the last alpha/beta versions (dev)
92
+ - release : contain the last rc versions (dev)
93
+ - feature-* : new feature to merge (dev)
94
+ - hotfixs-* : fix from release to merge with dev and X.Y (dev)
74
95
 
75
- ### Improve main tests
76
- - Add few tests for untested features
77
- - Improve existing tests (mainly on StringHelper)
78
96
 
79
97
  # Contributors
80
- - poulet_a : Creator and main developper. Feel free to ask me a question by email.
81
- email : arthur.poulet AT cryptolab.net [OpenPGP : 0x6D9EA34A]
98
+ - poulet_a : Creator and main developer. Feel free to ask me a question by email.
99
+ email: arthur.poulet AT cryptolab.net [OpenPGP : 0x6D9EA34A]
100
+ - bakhou_r : Developer from jerevedunemaison.com
@@ -7,8 +7,7 @@ module ArrayHelper
7
7
  # Exemple : ["a", "b", "c"].joini(["x", "y"]) => "axbyc"
8
8
  #
9
9
  # @raise [ArgumentError] if sep in not an array or a string
10
- # @param sep [Array] array of separators
11
- # @param sep [String] uniq separator (join alias {#join})
10
+ # @param sep [Array or String] array of separators or string as an uniq separator (join alias {#join})
12
11
  # @return [String] string joined
13
12
  def joini sep
14
13
  if sep.is_a? Array
@@ -57,7 +56,7 @@ module ArrayHelper
57
56
  #
58
57
  # @return [Integer] self.sum / self.size. 0 if no elements
59
58
  def average
60
- return (self.size > 0) ? (self.sum / self.size) : (0)
59
+ return (self.size > 0) ? (self.sum.to_f / self.size).round : (0)
61
60
  end
62
61
 
63
62
  # Same than {#average} but use to_f instead of to_i
@@ -1,3 +1,3 @@
1
1
  module RubyHelper
2
- VERSION = '1.2.3'
2
+ VERSION = '1.3.rc2'
3
3
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ module IntegerHelper
5
+
6
+ # return true if not odd
7
+ #
8
+ # @return [true or false]
9
+ def peer?
10
+ not odd?
11
+ end
12
+
13
+ end
14
+
15
+ class Integer
16
+ prepend IntegerHelper
17
+ end
@@ -44,6 +44,33 @@ module NumericHelper
44
44
  return self.replace(self.min(maximum_value))
45
45
  end
46
46
 
47
+ # return true if peer
48
+ # you can see also {#odd?}
49
+ #
50
+ # @return [true or false]
51
+ def peer?
52
+ return (self % 2).zero? ? true : false
53
+ end
54
+
55
+ # return true if odd
56
+ # you can see also {#peer?}
57
+ #
58
+ # @return [true or false]
59
+ def odd?
60
+ not peer?
61
+ end
62
+
63
+ # Not ready yet
64
+ #
65
+ # Resolve a simple 2sd degree equation
66
+ #
67
+ # @param a [Numeric] a*x**2+b*x+c = y
68
+ # @param b [Numeric] a*x**2+b*x+c = y
69
+ # @param c [Numeric] a*x**2+b*x+c = y
70
+ # @return [Array of Numeric]
71
+ # def self.solve_2d a, b=0, c=0
72
+ # end
73
+
47
74
  end
48
75
 
49
76
  class Numeric
@@ -110,24 +110,6 @@ module StringHelper
110
110
  return s.to_case(case_mod)
111
111
  end
112
112
 
113
- # improvement of to_f to count "," caracter as "."
114
- #
115
- # @return [Float] like {Integer#to_f}
116
- def to_fi
117
- return self.gsub(',', '.').to_f
118
- end
119
-
120
- # to_i with delimiter to remove
121
- # Example : "12.000.000".to_ii => 12000000
122
- #
123
- # @param char [String] char to delete (default : ' ')
124
- # @return [Integer] like {Integer#to_i]
125
- # @raise [ArgumentError] If (param char) is not a String
126
- def to_ii(char=' ')
127
- raise ArgumentError, "Argument is not a String" unless char.is_a? String
128
- self.delete(char).to_i
129
- end
130
-
131
113
  # CRYXOR (one time pad dirt application)
132
114
  #
133
115
  # @raise [ArgumentError] if key is not a valid String
@@ -191,17 +173,16 @@ module StringHelper
191
173
  end
192
174
  end
193
175
 
194
- # @raise [ArgumentError] via {#static}
195
176
  # see {#static}
177
+ #
178
+ # @raise [ArgumentError] via {#static}
196
179
  def static!(n, char=' ')
197
180
  return self.replace(self.static(n, char))
198
181
  end
199
182
 
200
183
  # Returns true or false if the string if "true" or "false". else nil
201
184
  #
202
- # @return [TrueClass] on self == "true"
203
- # @return [FalseClass] on self == "false"
204
- # @return [NilClass] else
185
+ # @return [true or false or nil]
205
186
  def to_t
206
187
  case self
207
188
  when "true"
@@ -213,50 +194,20 @@ module StringHelper
213
194
  end
214
195
  end
215
196
 
216
- # @return [TrueClass] if self == "true"
217
- # @return [FalseClass] else
197
+ # indicate if the string is "true"
198
+ #
199
+ # @return [true or false]
218
200
  def true?
219
201
  return (self == "true")
220
202
  end
221
203
 
222
- # @return [TrueClass] on self == "false"
223
- # @return [FalseClass] else
204
+ # indicate if the string is "false"
205
+ #
206
+ # @return [true or false]
224
207
  def false?
225
208
  return (self == "false")
226
209
  end
227
210
 
228
- # get only the digits and symbols in the string
229
- #
230
- # @param sign (true/false) if true, keep the - and + signs
231
- # @return [String] epured string
232
- def get_int(sign = true)
233
- return self.gsub(/[^\-\+\d]/, "") if sign == true
234
- return self.gsub(/[^\d]/, "")
235
- end
236
-
237
- # see {#get_int}
238
- #
239
- # @return [String]
240
- def get_int!(sign = true)
241
- return self.replace(self.get_int(sign))
242
- end
243
-
244
- # as get_int but with . and ,
245
- #
246
- # @param sign (true/false) if true, keep the - and + signs
247
- # @return [String] epured_string
248
- def get_float(sign = true)
249
- return self.gsub(/[^\-\+\d\.\,]/, "") if sign == true
250
- return self.gsub(/[^\d\.\,]/, "")
251
- end
252
-
253
- # see {#get_float}
254
- #
255
- # @return [String]
256
- def get_float!(sign = true)
257
- return self.replace(self.get_float(sign))
258
- end
259
-
260
211
  # Capitalize a sequence (each word)
261
212
  #
262
213
  # @return [String] capitalized_string
@@ -0,0 +1,163 @@
1
+ #encoding: utf-8
2
+
3
+ module StringNumericHelper
4
+
5
+ # improvement of to_f to count "," caracter as "."
6
+ #
7
+ # @return [Float] like {Integer#to_f}
8
+ def to_fi
9
+ return self.gsub(',', '.').to_f
10
+ end
11
+
12
+ # to_i with delimiter to remove
13
+ # Example : "12.000.000".to_ii => 12000000
14
+ #
15
+ # @param char [String] char to delete (default : ' ')
16
+ # @raise [ArgumentError] If (param char) is not a String
17
+ # @return [Integer] like {Integer#to_i]
18
+ def to_ii(char=' ')
19
+ raise ArgumentError, "Argument is not a String" unless char.is_a? String
20
+ self.delete(char).to_i
21
+ end
22
+
23
+ # It take every digits (and sign - see param sign) and return them
24
+ # you should see also {#get_float}
25
+ #
26
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
27
+ # @return [String] epured string
28
+ def get_int(sign = true)
29
+ return self.gsub(/[^\-\+\d]/, "") if sign == true
30
+ return self.gsub(/[^\-\d]/, "") if sign == :less
31
+ return self.gsub(/[^\d]/, "")
32
+ end
33
+
34
+ # see {#get_int}
35
+ #
36
+ # @return [String]
37
+ def get_int!(sign = true)
38
+ return self.replace(self.get_int(sign))
39
+ end
40
+
41
+ # It take every digits (and sign - see param sign) of the first
42
+ # group of digits and return them. For exemple, "+3 4".get_1int will return "+3"
43
+ # you should see also {#get_int} {#get_ints} and {#get_1float}
44
+ #
45
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
46
+ # @return [String] epured string
47
+ def get_1int(sign = true)
48
+ return self.match(/([\-\+]?\d+)/).to_a[1].to_s.get_int(sign) if sign == true
49
+ return self.match(/(\-?\d+)/).to_a[1].to_s.get_int(sign) if sign == :less
50
+ return self.match(/(\d+)/).to_a[1].to_s.get_int(sign)
51
+ end
52
+
53
+ # see {#get_1int}
54
+ #
55
+ # @return [String]
56
+ def get_1int!(sign = true)
57
+ return self.replace(self.get_1int(sign))
58
+ end
59
+
60
+ # get all digits into an array of string (split from self)
61
+ # if sep is a sign and the param sign == true, then theses signs will be splited first
62
+ # (if sep == '-' for example, "1-1".get_ints will return ["1", "1"]
63
+ # see also {#get_floats} and {#get_int}
64
+ #
65
+ # @param sep [String or Regexp] separator
66
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
67
+ # @raise ArgumentError if sep is not a String
68
+ # @return [Array of String]
69
+ def get_ints(sep = ' ', sign = true)
70
+ raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
71
+ return self.split(sep).map{|e| e.get_int(sign)}
72
+ end
73
+
74
+ # get all integer groups into an array of string (split from self)
75
+ # if sep is a sign and the param sign == true, then theses signs will be splited first
76
+ # see also {#get_ints} and {#get_1int}
77
+ #
78
+ # @param sep [String or Regexp] separator
79
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
80
+ # @raise ArgumentError if sep is not a String
81
+ # @return [Array of String]
82
+ def get_1ints(sep = ' ', sign = true)
83
+ raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
84
+ return self.split(sep).map{|e| e.get_1int(sign)}
85
+ end
86
+
87
+ # get every digits and + - . , symbols in the string
88
+ # you can also see {#to_fi} to turn the String into a Float
89
+ # see als {#get_1float} {#get_floats} and {#get_int}
90
+ #
91
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
92
+ # @return [String] epured_string
93
+ def get_float(sign = true)
94
+ return self.gsub(/[^\-\+\d\.\,]/, "") if sign == true
95
+ return self.gsub(/[^\-\d\.\,]/, "") if sign == :less
96
+ return self.gsub(/[^\d\.\,]/, "")
97
+ end
98
+
99
+ # see {#get_float}
100
+ #
101
+ # @return [String]
102
+ def get_float!(sign = true)
103
+ return self.replace(self.get_float(sign))
104
+ end
105
+
106
+ # get only the digits and + - . , symbols in the string from the first group of digits
107
+ # you should see also {#get_float} and {#get_1int}
108
+ #
109
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
110
+ # @return [String] epured string
111
+ def get_1float(sign = true)
112
+ return self.match(/([\d\.,\-\+]*\d[\d\.,\-\+]*)/).to_a[1].to_s.get_float(sign) if sign == true
113
+ return self.match(/([\d\.,\-]*\d[\d\.,\-]*)/).to_a[1].to_s.get_float(sign) if sign == :less
114
+ return self.match(/([\d\.,]*\d[\d\.,]*)/).to_a[1].to_s.get_float(sign)
115
+ end
116
+
117
+ # see {#get_1float}
118
+ #
119
+ # @return [String]
120
+ def get_1float!(sign = true)
121
+ return self.replace(self.get_1float(sign))
122
+ end
123
+
124
+ # get all digit and symboles from a splited string
125
+ # if sep is a sign and the param sign == true, then theses signs will be splited first
126
+ # see also {#get_1float} and {#get_floats}
127
+ #
128
+ # @param sep [String or Regexp] separator
129
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
130
+ # @raise ArgumentError if sep is not a String
131
+ # @return [Array of String]
132
+ def get_floats(sep = ' ', sign = true)
133
+ raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
134
+ return self.split(sep).map{|e| e.get_float(sign)}
135
+ end
136
+
137
+ # get all floats groups
138
+ # if sep is a sign and the param sign == true, then theses signs will be splited first
139
+ # see also {#get_float} and {#get_ints}
140
+ #
141
+ # @param sep [String or Regexp] separator
142
+ # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
143
+ # @raise ArgumentError if sep is not a String
144
+ # @return [Array of String]
145
+ def get_1floats(sep = ' ', sign = true)
146
+ raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
147
+ return self.split(sep).map{|e| e.get_1float(sign)}
148
+ end
149
+
150
+ # transforme the string into an float in m² if containing "ha"
151
+ #
152
+ # @return [Float]
153
+ def ha2m2
154
+ return self.gsub("m2", "").get_1float.to_fi unless self.match(/(\A|[^[:alpha:]])ha(\Z|[^[:alpha:]])/i)
155
+ return self.gsub("m2", "").get_1float.to_fi * 10_000 unless self.match(/(\A|[^[:alpha:]])m(2|²)(\Z|[^[:alpha:]])/i)
156
+ return self.gsub("m2", "").get_1float.to_fi
157
+ end
158
+
159
+ end
160
+
161
+ class String
162
+ prepend StringNumericHelper
163
+ end
data/lib/rubyhelper.rb CHANGED
@@ -3,8 +3,10 @@
3
3
  # simple extension
4
4
  require_relative 'rubyhelper/gem-version.rb'
5
5
  require_relative 'rubyhelper/string.rb'
6
+ require_relative 'rubyhelper/string_numeric.rb'
6
7
  require_relative 'rubyhelper/array.rb'
7
8
  require_relative 'rubyhelper/numeric.rb'
9
+ require_relative 'rubyhelper/integer.rb'
8
10
  require_relative 'rubyhelper/time.rb'
9
11
  require_relative 'rubyhelper/hash.rb'
10
12
 
@@ -12,4 +14,3 @@ require_relative 'rubyhelper/hash.rb'
12
14
  require_relative 'rubyhelper/argumenterror.rb'
13
15
 
14
16
  # new classes
15
- require_relative 'rubyhelper/versionhelper.rb'
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 = "Hotfix of get_float"
7
+ s.summary = "Improvements and additions by poulet_a to the basic ruby classes"
8
8
  s.description = "Improvements and additions by poulet_a to the basic ruby classes"
9
9
  s.authors = [
10
10
  "poulet_a"
@@ -14,12 +14,13 @@ Gem::Specification.new do |s|
14
14
  "lib/rubyhelper.rb",
15
15
  "lib/rubyhelper/gem-version.rb",
16
16
  "lib/rubyhelper/string.rb",
17
+ "lib/rubyhelper/string_numeric.rb",
17
18
  "lib/rubyhelper/array.rb",
18
19
  "lib/rubyhelper/numeric.rb",
20
+ "lib/rubyhelper/integer.rb",
19
21
  "lib/rubyhelper/time.rb",
20
22
  "lib/rubyhelper/hash.rb",
21
23
  "lib/rubyhelper/argumenterror.rb",
22
- "lib/rubyhelper/versionhelper.rb",
23
24
  "README.md",
24
25
  "Rakefile",
25
26
  "rubyhelper.gemspec",
@@ -27,7 +28,7 @@ Gem::Specification.new do |s|
27
28
  "test/test_hash.rb",
28
29
  "test/test_numeric.rb",
29
30
  "test/test_string.rb",
30
- "test/test_versionhelper.rb",
31
+ "test/test_string_numeric.rb",
31
32
  ]
32
33
  s.homepage = "https://gitlab.com/poulet_a/rubyhelper"
33
34
  s.license = "GNU/GPLv3"
data/test/test_array.rb CHANGED
@@ -19,6 +19,7 @@ class ArrayHelperTest < Minitest::Test
19
19
  def test_sum
20
20
  assert_equal(12, [1,2,9].sum)
21
21
  assert_equal(0, [].sum)
22
+ assert_equal(0, [-1,1].sum)
22
23
  end
23
24
 
24
25
  def test_sum_with_array
@@ -33,12 +34,17 @@ class ArrayHelperTest < Minitest::Test
33
34
  assert_equal(12.0, [1,2, 9].sumf)
34
35
  assert_equal(0.1, [0.01, 0.09, -0, -1, 1.1, -0.1].sumf.round(2))
35
36
  assert_equal(0.0, [].sumf)
37
+ end
38
+
39
+ def test_sumf_with_array
36
40
  assert_equal([2.0,3.0], [1,2].sumf([1,1,1]))
37
41
  assert_equal([], [].sumf([1,1,1]))
38
42
  end
39
43
 
40
44
  def test_average
41
45
  assert_equal(2, [1,2,3].average)
46
+ assert_equal(1, [1,1,1].average)
47
+ assert_equal(2, [1,2,2].average)
42
48
  end
43
49
 
44
50
  def test_averagef
data/test/test_numeric.rb CHANGED
@@ -28,4 +28,22 @@ class NumericHelperTest < Minitest::Test
28
28
  assert_equal(1, (2.2).max(1))
29
29
  end
30
30
 
31
+ def test_odd?
32
+ assert_equal(false, 0.0.odd?)
33
+ assert_equal(true, 1.1.odd?)
34
+ assert_equal(false, 2.0.odd?)
35
+ assert_equal(true, 3.0.odd?)
36
+ end
37
+
38
+ def test_peer?
39
+ assert_equal(true, 0.0.peer?)
40
+ assert_equal(false, 1.1.peer?)
41
+ assert_equal(true, 2.0.peer?)
42
+ assert_equal(false, 3.0.peer?)
43
+ end
44
+
45
+ def test_solve_2d
46
+ #assert_equal([0], Numeric.solve_2d(1,0,0))
47
+ end
48
+
31
49
  end
data/test/test_string.rb CHANGED
@@ -46,21 +46,6 @@ class StringHelperTest < Minitest::Test
46
46
  assert_equal("bonjour.", "bonjour€".to_ascii("."))
47
47
  end
48
48
 
49
- def test_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)
56
- end
57
-
58
- def test_to_ii
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\-"))
62
- end
63
-
64
49
  def test_static
65
50
  assert_equal("r", "bonjour".static(1, " "))
66
51
  assert_equal("our", "bonjour".static(3, " "))
@@ -98,18 +83,6 @@ class StringHelperTest < Minitest::Test
98
83
  assert_equal(false, "other".false?)
99
84
  end
100
85
 
101
- def test_get_int
102
- assert_equal("1312".get_int(), "1312")
103
- assert_equal("ea -ze 13e12 à nnazdaz d".get_int(), "-1312")
104
- assert_equal("ea\n ze +13\n12\n à nnazdaz\n\t\n\r d".get_int(), "+1312")
105
- end
106
-
107
- def test_get_int
108
- assert_equal("13,12".get_float(), "13,12")
109
- assert_equal("ea -ze 13e.12 à nnazdaz d".get_float(), "-13.12")
110
- assert_equal("ea\n ze +13\n.12\n à nnazdaz\n\t\n\r d".get_float(), "+13.12")
111
- end
112
-
113
86
  def test_scapitalize
114
87
  assert_equal("Bonjour Monsieur", "Bonjour Monsieur".scapitalize)
115
88
  assert_equal("Bonjour M A D & A", "BONJOUR M A D & A".scapitalize)
@@ -122,6 +95,7 @@ class StringHelperTest < Minitest::Test
122
95
  assert_equal(["bonjour", "à", "toi"], "\nbonjour\n\nà\n\ntoi\n\n\r".splity)
123
96
  assert_equal(["bonjour", "à", "toi"], "bonjourXàXtoiX".splity("X"))
124
97
  assert_equal(["bonjour", "à", "toi"], "bonjourXàYtoiX".splity(/X|Y/))
98
+ assert_equal(["bonjour", "à", "toi"], "\t\t\r\n\r\tbonjour\t\r\n\r\tà\r\t\n\t\rtoi\t\n\r\t\n\t\r".splity)
125
99
  end
126
100
 
127
101
  end
@@ -0,0 +1,103 @@
1
+ #encoding: utf-8
2
+ require 'minitest/autorun'
3
+ require_relative '../lib/rubyhelper'
4
+
5
+ class StringNumericHelperTest < Minitest::Test
6
+
7
+ def test_to_fi
8
+ assert_equal(0.0, "bonjour".to_fi)
9
+ assert_equal(0.0, "bonj1our".to_fi)
10
+ assert_equal(1.1, "1.1.1".to_fi)
11
+ assert_equal(1.1, "1.1".to_fi)
12
+ assert_equal(1.1, "1,1".to_fi)
13
+ assert_equal(0.1, ",1,1".to_fi)
14
+ end
15
+
16
+ def test_to_ii
17
+ assert_equal(11, "1 1".to_ii())
18
+ assert_equal(60868, "06.08.68".to_ii("."))
19
+ assert_equal(60868, "06.08.68".to_ii("\. \t\-"))
20
+ end
21
+
22
+ def test_get_int
23
+ assert_equal("1312", "1312".get_int())
24
+ assert_equal("-1312", "ea -ze 13e12 à nnazdaz d".get_int())
25
+ assert_equal("+1312", "ea\n ze +13\n12\n à nnazdaz\n\t\n\r d".get_int())
26
+ assert_equal("1312", "ea\n ze -13\n12\n à nnazdaz\n\t\n\r d".get_int(false))
27
+ assert_equal("-1312", "ea\n ze -13\n12\n à nnazdaz\n\t\n\r d".get_int(:less))
28
+ assert_equal("1312", "ea\n ze +13\n12\n à nnazdaz\n\t\n\r d".get_int(false))
29
+ end
30
+
31
+ def test_get_1int
32
+ assert_equal("1312", "1312".get_1int())
33
+ assert_equal("-13", "ea -ze -13e12 à nnazdaz d".get_1int())
34
+ assert_equal("13", "13ea -ze -13e12 à nnazdaz d".get_1int())
35
+ assert_equal("13", "ea -ze -13e12 à nnazdaz d".get_1int(false))
36
+ assert_equal("-13", "ea -ze -13e12 à nnazdaz d".get_1int(:less))
37
+ assert_equal("13", "ea -ze 13-13e12 à nnazdaz d".get_1int(false))
38
+ end
39
+
40
+ def test_get_ints
41
+ assert_equal(["1", "-3", "+12"], "1 -3 +12".get_ints())
42
+ assert_equal(["1", "-3", "+12"], "a1;aaa -3eze +1ez2ez".get_ints())
43
+ assert_equal(["1", "3+12"], "1 -3 +12".get_ints('-'))
44
+ end
45
+
46
+ def test_get_1ints
47
+ assert_equal(["1", "-3", "+12"], "1 -3 +12".get_1ints())
48
+ assert_equal(["1", "-3", "+1"], "a1;aaa -3eze +1ez2ez".get_1ints())
49
+ assert_equal(["1", "3"], "1 -3 +12".get_1ints('-'))
50
+ end
51
+
52
+ def test_get_float
53
+ assert_equal("13,12", "13,12".get_float())
54
+ assert_equal("-13.12", "ea -ze 13e.12 à nnazdaz d".get_float())
55
+ assert_equal("+13.12", "ea\n ze +13\n.12\n à nnazdaz\n\t\n\r d".get_float())
56
+ assert_equal("-13.12", "ea\n ze -13\n.12\n à nnazdaz\n\t\n\r d".get_float())
57
+ assert_equal("--13.12", "ea\n ze- -13\n.12\n à nnazdaz\n\t\n\r d".get_float())
58
+ assert_equal("13.12", "ea\n ze- -13\n.12\n à nnazdaz\n\t\n\r d".get_float(false))
59
+ assert_equal("--13.12", "ea\n ze- -13\n.12\n à nnazdaz\n\t\n\r d".get_float(:less))
60
+ end
61
+
62
+ def test_get_1float
63
+ assert_equal("1312.1", "1312.1".get_1float())
64
+ assert_equal("-13,2", "ea -ze -13,2e12,2 à nnazdaz d".get_1float())
65
+ assert_equal("13,12", "13,12ea -ze -13,12e12,13 à nnazdaz d".get_1float())
66
+ assert_equal("13.0", "ea -ze -13.0e12 à nnazdaz d".get_1float(false))
67
+ assert_equal("13.", "ea -ze 13.-13.1e12.2 à nnazdaz d".get_1float(false))
68
+ assert_equal("-13.1", "ea -ze -13.1e12.2 à nnazdaz d".get_1float(:less))
69
+ end
70
+
71
+ def test_get_floats
72
+ assert_equal(["1", "-3", "+12"], "1 -3 +12".get_floats())
73
+ assert_equal(["1", "-3.1", "+12"], "a1;aaa -3.1eze +1ez2ez".get_floats())
74
+ assert_equal(["1", "3+12,2"], "1 -3 +12,2".get_floats('-'))
75
+ end
76
+
77
+ def test_get_1floats
78
+ assert_equal(["1", "-3", "+12"], "1 -3 +12".get_1floats())
79
+ assert_equal(["1", "-3.1", "+1"], "a1;aaa -3.1eze +1ez2ez".get_1floats())
80
+ assert_equal(["1", "3,1"], "1 -3,1 +12,2".get_1floats('-'))
81
+ end
82
+
83
+ def test_ha2m2
84
+ #simple match
85
+ assert_equal(10_000.0, "1 ha".ha2m2)
86
+ assert_equal(10_000.0, "1 Ha".ha2m2)
87
+ assert_equal(10_000.0, "ha 1".ha2m2)
88
+ assert_equal(10_000.0, "1ha".ha2m2)
89
+
90
+ #advanced match
91
+ assert_equal(12000, "1.2 Ha".ha2m2)
92
+ assert_equal(12000, " 1,200 Ha".ha2m2)
93
+
94
+ #not match
95
+ assert_equal(1.0, "1 m2".ha2m2)
96
+ assert_equal(1.0, "1 h a".ha2m2)
97
+
98
+ #not match advanced
99
+ assert_equal(1.0, "1 m2 (+ 1 ha)".ha2m2)
100
+ assert_equal(50.0, "50.0 m² without the 1 ha of eastead".ha2m2)
101
+ end
102
+
103
+ end
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- >�<R� 9�Z�����(���@��+Ҷ������ް/喎:Zպ�sҸ�4d���y��1�l449P_>{������%KX�aWld�rX'np�R��~���y(��Q0������U���K�����=�S��A隤���|&��J(#[ ��#4-���ٮ���p�{p%P�#?4U~�K�( "ɞ�%^�j
1
+ w��I2�韔��}�-F3��'����(n0^幜�I� 0���������u��M��aFw�{"Di���S{��jU�_l�l'Rn8U\��e���*�+���b��+:=b�;�N��@J\���#O������"�w8��yW霢�i WPju�ݴ��v�V�A,�k�x��!�\q�V�����h�ha߾�}̳.�R�P�SBӼ ktH{�y|��N�H�Ձ�ޱ��=? Z��,R(0n�L
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.2.3
4
+ version: 1.3.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -31,7 +31,7 @@ cert_chain:
31
31
  +lG6tRo8QaFrH3afOmy4VUaG84Jm1XjNYnyaOfLb9ItpcQgVySn2c3aJ2PLcPljM
32
32
  EhZUryAiV8KNMQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-09-11 00:00:00.000000000 Z
34
+ date: 2014-09-12 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description: Improvements and additions by poulet_a to the basic ruby classes
37
37
  email:
@@ -39,12 +39,13 @@ email:
39
39
  - - lib/rubyhelper.rb
40
40
  - lib/rubyhelper/gem-version.rb
41
41
  - lib/rubyhelper/string.rb
42
+ - lib/rubyhelper/string_numeric.rb
42
43
  - lib/rubyhelper/array.rb
43
44
  - lib/rubyhelper/numeric.rb
45
+ - lib/rubyhelper/integer.rb
44
46
  - lib/rubyhelper/time.rb
45
47
  - lib/rubyhelper/hash.rb
46
48
  - lib/rubyhelper/argumenterror.rb
47
- - lib/rubyhelper/versionhelper.rb
48
49
  - README.md
49
50
  - Rakefile
50
51
  - rubyhelper.gemspec
@@ -52,7 +53,7 @@ email:
52
53
  - test/test_hash.rb
53
54
  - test/test_numeric.rb
54
55
  - test/test_string.rb
55
- - test/test_versionhelper.rb
56
+ - test/test_string_numeric.rb
56
57
  executables: []
57
58
  extensions: []
58
59
  extra_rdoc_files: []
@@ -64,16 +65,17 @@ files:
64
65
  - lib/rubyhelper/array.rb
65
66
  - lib/rubyhelper/gem-version.rb
66
67
  - lib/rubyhelper/hash.rb
68
+ - lib/rubyhelper/integer.rb
67
69
  - lib/rubyhelper/numeric.rb
68
70
  - lib/rubyhelper/string.rb
71
+ - lib/rubyhelper/string_numeric.rb
69
72
  - lib/rubyhelper/time.rb
70
- - lib/rubyhelper/versionhelper.rb
71
73
  - rubyhelper.gemspec
72
74
  - test/test_array.rb
73
75
  - test/test_hash.rb
74
76
  - test/test_numeric.rb
75
77
  - test/test_string.rb
76
- - test/test_versionhelper.rb
78
+ - test/test_string_numeric.rb
77
79
  homepage: https://gitlab.com/poulet_a/rubyhelper
78
80
  licenses:
79
81
  - GNU/GPLv3
@@ -89,14 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
91
  version: '0'
90
92
  required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  requirements:
92
- - - ">="
94
+ - - ">"
93
95
  - !ruby/object:Gem::Version
94
- version: '0'
96
+ version: 1.3.1
95
97
  requirements: []
96
98
  rubyforge_project:
97
99
  rubygems_version: 2.4.1
98
100
  signing_key:
99
101
  specification_version: 4
100
- summary: Hotfix of get_float
102
+ summary: Improvements and additions by poulet_a to the basic ruby classes
101
103
  test_files: []
102
104
  has_rdoc:
metadata.gz.sig CHANGED
Binary file
@@ -1,94 +0,0 @@
1
- #encoding: utf-8
2
-
3
- module VersionHelper
4
-
5
- class Version
6
-
7
- attr_accessor :v
8
-
9
- # [Integer] : 1234 => 1.2.3.4
10
- # [String] : "1.2-3" => 1.2.3
11
- # [Array] : like multiple arguments
12
- # [multiple] : each argument is converted to a number 1,2,3 => 1.2.3
13
- #
14
- # @param arg : list of arguments
15
- def initialize(*arg)
16
- @v = []
17
- if arg.size == 1
18
- v = arg.first
19
- case v.class.to_s
20
- when 'String'
21
- v.gsub!(/\A\D/, '')
22
- v.gsub!(/\D/, '.')
23
- @v = v.split('.').map{|e| e.to_i}
24
- when 'Array'
25
- @v = v.map{|e| e.to_i}
26
- when 'Fixnum'
27
- v = v.to_i
28
- loop do
29
- break if v == 0
30
- @v << (v % 10)
31
- v /= 10
32
- end
33
- else
34
- raise ArgumentError, v.class.to_s
35
- end
36
- end
37
- if arg.size > 1
38
- @v = arg.map{|e| e.to_i}
39
- end
40
- end
41
-
42
- def incr!(n=-1)
43
- @v[n] = @v[n] += 1
44
- end
45
-
46
- def decr!(n=-1)
47
- @v[n] = @v[n] -= 1
48
- end
49
-
50
- def to_a
51
- return Version.to_a(self)
52
- end
53
-
54
- def to_s
55
- return Version.to_s(self)
56
- end
57
-
58
- # Not work yet
59
- def to_h
60
- return Version.to_h(self)
61
- end
62
-
63
- def to_i
64
- return Version.to_i(self)
65
- end
66
-
67
- #Return an array with each number of the version
68
- def self.to_a(version)
69
- raise ArgumentError unless version.is_a? Version
70
- return version.v.dup
71
- end
72
-
73
- #Return an string with each number of the version, joined by '.'
74
- def self.to_s(version)
75
- raise ArgumentError unless version.is_a? Version
76
- return version.v.join('.')
77
- end
78
-
79
- #Not work yet
80
- def self.to_h(version)
81
- raise ArgumentError unless version.is_a? Version
82
- return nil
83
- end
84
-
85
- #Return an integer with each number of the version
86
- def self.to_i(version)
87
- raise ArgumentError unless version.is_a? Version
88
- i = 0
89
- version.v.each{|e| i = i * 10 + e}
90
- return i
91
- end
92
- end
93
-
94
- end
@@ -1,59 +0,0 @@
1
- #encoding: utf-8
2
- require 'minitest/autorun'
3
- require_relative '../lib/rubyhelper'
4
-
5
- class VersionHelperTest < Minitest::Test
6
-
7
- def test_new
8
- v1 = VersionHelper::Version.new 1
9
- v2 = VersionHelper::Version.new [1,2]
10
- v3 = VersionHelper::Version.new "v1,2.3"
11
- v4 = VersionHelper::Version.new 123
12
- end
13
-
14
- def test_incr!
15
- v1 = VersionHelper::Version.new 1
16
- v2 = VersionHelper::Version.new 1,2
17
- v3 = VersionHelper::Version.new 1,2,3
18
- v1.incr!
19
- v2.incr!
20
- v3.incr!
21
- end
22
-
23
- def test_decr!
24
- v1 = VersionHelper::Version.new 1
25
- v2 = VersionHelper::Version.new 1,2
26
- v3 = VersionHelper::Version.new 1,2,3
27
- v1.decr!
28
- v2.decr!
29
- v3.decr!
30
- end
31
-
32
- def test_to_i
33
- v1 = VersionHelper::Version.new 1
34
- v2 = VersionHelper::Version.new 1,2
35
- v3 = VersionHelper::Version.new 1,2,3
36
- assert_equal(1, v1.to_i)
37
- assert_equal(12, v2.to_i)
38
- assert_equal(123, v3.to_i)
39
- end
40
-
41
- def test_to_s
42
- v1 = VersionHelper::Version.new 1
43
- v2 = VersionHelper::Version.new 1,2
44
- v3 = VersionHelper::Version.new 1,2,3
45
- assert_equal("1", v1.to_s)
46
- assert_equal("1.2", v2.to_s)
47
- assert_equal("1.2.3", v3.to_s)
48
- end
49
-
50
- def test_to_a
51
- v1 = VersionHelper::Version.new 1
52
- v2 = VersionHelper::Version.new 1,2
53
- v3 = VersionHelper::Version.new 1,2,3
54
- assert_equal([1], v1.to_a)
55
- assert_equal([1,2], v2.to_a)
56
- assert_equal([1,2,3], v3.to_a)
57
- end
58
-
59
- end