rubyhelper 1.3.0 → 1.4.0

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: b4992284db42715a27e0a49849de7e22615379d4
4
- data.tar.gz: 32e5fe7c91a2c67b7f1c5315c2e025aa6a21f0a6
3
+ metadata.gz: 81a9ac3a82da7a389de889f1c0542d378126a4c3
4
+ data.tar.gz: e01218faa33dd5e1efc472d70a42efbf0d9b0955
5
5
  SHA512:
6
- metadata.gz: 4feda99bf0f13dbf7eafb65c830d420a0482cb3af2a0b4f93346f8146ce81bd07305458c276f7ec1b5c5d36b739c15d3311b9193cea7e2ebabe16773be4d4a44
7
- data.tar.gz: 0a47c4a84f950edd028e0d2192d24cc80b9b804ad65040d7865a28b34a5daef8ea801bb97a55f2bae74ad2319c9afafec2000ae3beb39f72d4db96186efc0820
6
+ metadata.gz: 2fbc6fe1995fd1982ada3a105e0194a80f1adfce93cfffbffc2acf6d0c53ef0c9401404700403f6a276b19ab10e3bb49a50b4acc5fa91ec74459ec31f671a3d9
7
+ data.tar.gz: a98c2506c211236612109386c62953c19afbac51570d9f0c59282394965971eee31b4625344c460892816e655e1ad47fe6994941cabf77054f16af7f77f314c1
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  Last Stable Gem
4
4
  [![Gem Version](https://badge.fury.io/rb/rubyhelper.svg)](http://badge.fury.io/rb/rubyhelper)
5
5
 
6
- Last release **v1.2** ===> see the branch **#master**
7
- Last develop **v1.3** ===> see the branch **#dev**
6
+ Last release **v1.3** ===> see the branch **#master**
7
+ Last develop **v1.4** ===> see the branch **#dev**
8
8
 
9
9
  You can see the documentation here : http://rubydoc.info/gems/rubyhelper
10
10
  The source code is available here : https://gitlab.com/poulet_a/rubyhelper
@@ -39,9 +39,11 @@ in this gem ;)
39
39
  Simple and usefull integer average (*averagef for Float version*)
40
40
  - **Array.new.sum** => Integer
41
41
  Simple and usefull integer sum (*sumf for Float version*)
42
+ - **Array.new.strip** => Array
43
+ Split every Strings of the Array :)
42
44
 
43
45
 
44
- ## Notes about the source code
46
+ ## Development cycle
45
47
  The following sources code is not only my stuff, but also an implementation of
46
48
  idea found on stackoverflow, ...
47
49
 
@@ -69,32 +71,34 @@ The developpement running like that :
69
71
  16. Publish the new release vX.Y.Z if needed
70
72
 
71
73
 
74
+ ## Note about the development
75
+
72
76
  **Note about the first time developpement**
73
77
  I didn't predict to keep this gem in dev so the first part of the dev
74
78
  is a little messy. Don't look back 1.1 ;)
75
79
 
76
-
77
- ## Note about the development
78
- ###Version
80
+ ### Versions
79
81
  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
82
+ - X : major version, not compatible very with the previous. Lot of changes
83
+ - X.Y : minor version, new features, almost fully compatible with other X.Y
84
+ - X.Y.Z : release improvement, fix bugs, fully compatible with X.Y.Z
83
85
 
84
86
  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.
87
+ - X.Y-alphaN : 1th dev part. Dev new features
88
+ - X.Y-betaN : 2sd part. Dev tests, documentation, improvements, fix, few other feats
89
+ - X.Y-rcN : last part. Fixs, documentation, and tests only.
88
90
 
89
91
  ### 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)
92
+ - master : contain the last vX.Y.Z version published (stable)
93
+ - dev : contain the last alpha/beta versions (dev)
94
+ - release-X.Y : contain the last rc versions (dev)
95
+ - feature-*_NN : new feature to merge (dev)
94
96
  - hotfixs-* : fix from release to merge with dev and X.Y (dev)
95
97
 
96
98
 
97
99
  # Contributors
98
100
  - poulet_a : Creator and main developer. Feel free to ask me a question by email.
101
+ - Researchs, Tests, Documentation, Feature, Lead development
99
102
  email: arthur.poulet AT cryptolab.net [OpenPGP : 0x6D9EA34A]
100
103
  - bakhou_r : Developer from jerevedunemaison.com
104
+ - few Tests and Features
@@ -0,0 +1,6 @@
1
+ module RubyHelper
2
+
3
+ # Version cheat :)
4
+ VERSION = '1.4.0'
5
+
6
+ end
data/lib/rubyhelper.rb CHANGED
@@ -1,16 +1,18 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # Version
4
+ require_relative 'gem-version.rb'
5
+
3
6
  # simple extension
4
- require_relative 'rubyhelper/gem-version.rb'
5
7
  require_relative 'rubyhelper/string.rb'
6
8
  require_relative 'rubyhelper/string_numeric.rb'
7
9
  require_relative 'rubyhelper/array.rb'
8
10
  require_relative 'rubyhelper/numeric.rb'
9
- require_relative 'rubyhelper/integer.rb'
11
+ require_relative 'rubyhelper/fixnum.rb'
10
12
  require_relative 'rubyhelper/time.rb'
11
13
  require_relative 'rubyhelper/hash.rb'
12
14
 
13
15
  # extension advanced
14
- require_relative 'rubyhelper/argumenterror.rb'
16
+ # require_relative 'rubyhelper/argumenterror.rb'
15
17
 
16
18
  # new classes
@@ -118,6 +118,38 @@ module ArrayHelper
118
118
  return self[0..(size/2+size%2-1)].zip(self[(size/2+size%2)..-1])
119
119
  end
120
120
 
121
+ # try to use the method split on every element of the array
122
+ #
123
+ # @return [Array]
124
+ def strip
125
+ self.do(:strip)
126
+ end
127
+
128
+ # see {#split}
129
+ #
130
+ # @return [Array]
131
+ def split!
132
+ self.replace(self.strip)
133
+ end
134
+
135
+ # try to use the method (param method_to_exec) on every element of the array
136
+ #
137
+ # @raise ArgumentError if argument is not a string/symbol
138
+ # @param method_to_exec [String or Symbol] method name
139
+ # @return [Array]
140
+ def do(method_to_exec)
141
+ raise ArgumentError, "method_to_exec is not a valid Method" unless method_to_exec.is_a? String or method_to_exec.is_a? Symbol
142
+ self.map{|e| ((e.respond_to? method_to_exec) ? (e.public_send(method_to_exec)) : (e)) }
143
+ end
144
+
145
+ # see {#do}
146
+ #
147
+ # @raise ArgumentError via {#do}
148
+ # @return [Array]
149
+ def do!(method_to_exec)
150
+ self.replace(self.do(method_to_exec))
151
+ end
152
+
121
153
  end
122
154
 
123
155
  class Array
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ module FixnumHelper
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 Fixnum
16
+ prepend FixnumHelper
17
+ end
18
+
19
+ class Fixnum
20
+ # Add the possibility to add a Fixnum with a String
21
+ # It will change the fixnum into a string
22
+ # If the argument is not a String, it will use the normal + operation
23
+ alias_method :old_add, :+
24
+ def +(p)
25
+ return self.to_s + p if p.is_a? String
26
+ return self.old_add(p)
27
+ end
28
+ end
@@ -141,35 +141,40 @@ module StringHelper
141
141
  # Get a str with a static length.
142
142
  # If the str size > n, reduce the str (keep str from the (param place) )
143
143
  # You should check the test files for examples
144
- # Note : {#center} {#left} and {#right} do a similar work.
144
+ # if the (param place) is not valid, the function will just return self
145
+ # Note : {#center} {#ljust} and {#rjust} do a similar work.
145
146
  #
146
147
  # @raise [ArgumentError] if n in not an integer/char a String
147
148
  # @param n [Integer] number of char
148
149
  # @param char [String] char to replace if the initial str is too short
149
- # @param place [Symbol] :begin/:front :end/:back :center/:middle
150
+ # @param place [Symbol] :begin/:front/:left :end/:back/:rigth :center/:middle
150
151
  # @return [String]
151
- def static(n, char=' ', place= :back)
152
+ def static(n, char =' ', place = :right)
152
153
  raise ArgumentError, 'char is not an Char (String)' unless char.is_a? String
153
154
  raise ArgumentError, 'n is not an Integer' unless n.is_a? Integer
154
155
  char = char[0] || " " # get only the first char or a space if empty
155
156
  if size < n
156
157
  case place
157
- when :begin, :front
158
+ when :begin, :front, :left
158
159
  return char * (n - size).to_i + self
159
160
  when :center, :middle
160
161
  return char * ((n - size) / 2) + self + char * ((n - size) / 2 + (n - size) % 2)
161
- else
162
+ when :end, :back, :right
162
163
  return self + char * (n - size).to_i
164
+ else
165
+ return self
163
166
  end
164
167
  else
165
168
  case place
166
- when :begin, :front
169
+ when :begin, :front, :left
167
170
  return self[0...n]
168
171
  when :center, :middle
169
172
  return self[((-(size() +n - 1)) / 2)..((-(size() -n + 1)) / 2)]
170
- else
173
+ when :end, :back, :right
171
174
  return self[(-n)..(-1)]
172
- end
175
+ else
176
+ return self
177
+ end
173
178
  end
174
179
  end
175
180
 
@@ -12,8 +12,8 @@ module StringNumericHelper
12
12
  # to_i with delimiter to remove
13
13
  # Example : "12.000.000".to_ii => 12000000
14
14
  #
15
- # @param char [String] char to delete (default : ' ')
16
15
  # @raise [ArgumentError] If (param char) is not a String
16
+ # @param char [String] char to delete (default : ' ')
17
17
  # @return [Integer] like {Integer#to_i]
18
18
  def to_ii(char=' ')
19
19
  raise ArgumentError, "Argument is not a String" unless char.is_a? String
@@ -26,9 +26,9 @@ module StringNumericHelper
26
26
  # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
27
27
  # @return [String] epured string
28
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]/, "")
29
+ return self.gsub(/[^\-\+\d]/, '') if sign == true
30
+ return self.gsub(/[^\-\d]/, '') if sign == :less
31
+ return self.gsub(/[^\d]/, '')
32
32
  end
33
33
 
34
34
  # see {#get_int}
@@ -42,19 +42,23 @@ module StringNumericHelper
42
42
  # group of digits and return them. For exemple, "+3 4".get_1int will return "+3"
43
43
  # you should see also {#get_int} {#get_ints} and {#get_1float}
44
44
  #
45
+ # @raise ArgumentError if sep not a String
45
46
  # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
47
+ # @param sep [String]
46
48
  # @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)
49
+ def get_1int(sign = true, sep = '')
50
+ raise ArgumentError, "sep must be a String" unless sep.is_a? String
51
+ return self.delete(sep).match(/([\-\+]?\d+)/).to_a[1].to_s.get_int(sign) if sign == true
52
+ return self.delete(sep).match(/(\-?\d+)/).to_a[1].to_s.get_int(sign) if sign == :less
53
+ return self.delete(sep).match(/(\d+)/).to_a[1].to_s.get_int(sign)
51
54
  end
52
55
 
53
56
  # see {#get_1int}
54
57
  #
58
+ # @raise ArgumentError if sep not a String
55
59
  # @return [String]
56
- def get_1int!(sign = true)
57
- return self.replace(self.get_1int(sign))
60
+ def get_1int!(sign = true, sep = '')
61
+ return self.replace(self.get_1int(sign, sep))
58
62
  end
59
63
 
60
64
  # get all digits into an array of string (split from self)
@@ -62,12 +66,12 @@ module StringNumericHelper
62
66
  # (if sep == '-' for example, "1-1".get_ints will return ["1", "1"]
63
67
  # see also {#get_floats} and {#get_int}
64
68
  #
69
+ # @raise ArgumentError if sep is not a String
65
70
  # @param sep [String or Regexp] separator
66
71
  # @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
72
  # @return [Array of String]
69
73
  def get_ints(sep = ' ', sign = true)
70
- raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
74
+ raise ArgumentError, 'sep must be a String or a Regexp' unless sep.is_a? String or sep.is_a? Regexp
71
75
  return self.split(sep).map{|e| e.get_int(sign)}
72
76
  end
73
77
 
@@ -75,13 +79,14 @@ module StringNumericHelper
75
79
  # if sep is a sign and the param sign == true, then theses signs will be splited first
76
80
  # see also {#get_ints} and {#get_1int}
77
81
  #
78
- # @param sep [String or Regexp] separator
82
+ # @raise ArgumentError if firstsep is not a String or if sep is not a String/Regexp
83
+ # @param firstsep [String or Regexp] separator
79
84
  # @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
85
+ # @param sep [String] separator for {#get_1int}
81
86
  # @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)}
87
+ def get_1ints(firstsep = ' ', sign = true, sep = '')
88
+ raise ArgumentError, "firstsep must be a String" unless firstsep.is_a? String or firstsep.is_a? Regexp
89
+ return self.split(firstsep).map{|e| e.get_1int(sign, sep)}
85
90
  end
86
91
 
87
92
  # get every digits and + - . , symbols in the string
@@ -91,9 +96,9 @@ module StringNumericHelper
91
96
  # @param sign [true or false or :less ] if true, keep the - and + signs, if :less, only keep -
92
97
  # @return [String] epured_string
93
98
  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\.\,]/, "")
99
+ return self.gsub(/[^\-\+\d\.\,]/, '') if sign == true
100
+ return self.gsub(/[^\-\d\.\,]/, '') if sign == :less
101
+ return self.gsub(/[^\d\.\,]/, '')
97
102
  end
98
103
 
99
104
  # see {#get_float}
@@ -125,9 +130,9 @@ module StringNumericHelper
125
130
  # if sep is a sign and the param sign == true, then theses signs will be splited first
126
131
  # see also {#get_1float} and {#get_floats}
127
132
  #
133
+ # @raise ArgumentError if sep is not a String
128
134
  # @param sep [String or Regexp] separator
129
135
  # @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
136
  # @return [Array of String]
132
137
  def get_floats(sep = ' ', sign = true)
133
138
  raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
@@ -138,9 +143,9 @@ module StringNumericHelper
138
143
  # if sep is a sign and the param sign == true, then theses signs will be splited first
139
144
  # see also {#get_float} and {#get_ints}
140
145
  #
146
+ # @raise ArgumentError if sep is not a String
141
147
  # @param sep [String or Regexp] separator
142
148
  # @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
149
  # @return [Array of String]
145
150
  def get_1floats(sep = ' ', sign = true)
146
151
  raise ArgumentError, "sep must be a String" unless sep.is_a? String or sep.is_a? Regexp
@@ -151,9 +156,12 @@ module StringNumericHelper
151
156
  #
152
157
  # @return [Float]
153
158
  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
159
+ v = self.get_1float
160
+ return String.new if v.empty?
161
+ m2_i = self.index(/m(2|²)/i)
162
+ ha_i = self.index(/ha/i)
163
+ return v.to_fi if ha_i.nil? or (not m2_i.nil? and m2_i < ha_i)
164
+ return v.to_fi * 10_000
157
165
  end
158
166
 
159
167
  end
@@ -161,3 +169,14 @@ end
161
169
  class String
162
170
  prepend StringNumericHelper
163
171
  end
172
+
173
+ class String
174
+ # Add the possibility to add a String with a Fixnum
175
+ # It will change the fixnum into a string
176
+ # If the argument is not a Fixnum, it will use the normal + operation
177
+ alias_method :old_add, :+
178
+ def +(p)
179
+ return self + p.to_s if p.is_a? Fixnum
180
+ return self.old_add(p)
181
+ end
182
+ end
data/rubyhelper.gemspec CHANGED
@@ -1,10 +1,10 @@
1
- require_relative "lib/rubyhelper/gem-version"
1
+ require_relative "lib/gem-version"
2
2
 
3
3
  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 = "Improvements and additions by poulet_a to the basic ruby classes"
7
+ s.summary = "See Changelog"
8
8
  s.description = "Improvements and additions by poulet_a to the basic ruby classes"
9
9
  s.authors = [
10
10
  "poulet_a"
@@ -12,21 +12,22 @@ Gem::Specification.new do |s|
12
12
  s.email = "poulet_a@epitech.eu",
13
13
  s.files = [
14
14
  "lib/rubyhelper.rb",
15
- "lib/rubyhelper/gem-version.rb",
15
+ "lib/gem-version.rb",
16
16
  "lib/rubyhelper/string.rb",
17
17
  "lib/rubyhelper/string_numeric.rb",
18
18
  "lib/rubyhelper/array.rb",
19
19
  "lib/rubyhelper/numeric.rb",
20
- "lib/rubyhelper/integer.rb",
20
+ "lib/rubyhelper/fixnum.rb",
21
21
  "lib/rubyhelper/time.rb",
22
22
  "lib/rubyhelper/hash.rb",
23
- "lib/rubyhelper/argumenterror.rb",
23
+ # "lib/rubyhelper/argumenterror.rb",
24
24
  "README.md",
25
25
  "Rakefile",
26
26
  "rubyhelper.gemspec",
27
27
  "test/test_array.rb",
28
28
  "test/test_hash.rb",
29
29
  "test/test_numeric.rb",
30
+ "test/test_fixnum.rb",
30
31
  "test/test_string.rb",
31
32
  "test/test_string_numeric.rb",
32
33
  ]
data/test/test_array.rb CHANGED
@@ -10,7 +10,7 @@ class ArrayHelperTest < Minitest::Test
10
10
  assert_equal("s.S.s.S", ["s","S","s","S"].joini("."))
11
11
  end
12
12
 
13
- def test_joini_error
13
+ def test_joini_raise
14
14
  assert_raises ArgumentError do
15
15
  [].joini 1
16
16
  end
@@ -22,6 +22,16 @@ class ArrayHelperTest < Minitest::Test
22
22
  assert_equal(0, [-1,1].sum)
23
23
  end
24
24
 
25
+ def test_sum_arg
26
+ assert_equal([4,4,4], [1,2,3].sum([3,2,1]))
27
+ end
28
+
29
+ def test_sum_raise
30
+ assert_raises ArgumentError do
31
+ [].sum 1
32
+ end
33
+ end
34
+
25
35
  def test_sum_with_array
26
36
  assert_equal([2,3,4], [1,2,3].sum([1,1,1]))
27
37
  assert_equal([2,3,3], [1,2,3].sum([1,1]))
@@ -68,4 +78,13 @@ class ArrayHelperTest < Minitest::Test
68
78
  assert_equal([[:a, 2], [:b, 3], [:c, 4], [1, nil]], [:a, :b, :c, 1, 2, 3, 4].mirror)
69
79
  end
70
80
 
81
+ def test_strip
82
+ assert_equal(["test", "test", "test"], [" test ", "test \n", " \t test "].do(:strip))
83
+ end
84
+
85
+ def test_do
86
+ assert_equal(["test", "test", "test"], [" test ", "test \n", " \t test "].do(:strip))
87
+ assert_equal([["test"], ["test"], ["test"]], [" test ", "test \n", " \t test "].do(:split))
88
+ end
89
+
71
90
  end
@@ -0,0 +1,24 @@
1
+ #encoding: utf-8
2
+ require 'minitest/autorun'
3
+ require_relative '../lib/rubyhelper'
4
+
5
+ class FixnumHelperTest < Minitest::Test
6
+
7
+ def test_peer?
8
+ assert_equal(true, 0.peer?)
9
+ assert_equal(false, 1.peer?)
10
+ assert_equal(true, 2.peer?)
11
+ assert_equal(false, 3.peer?)
12
+ end
13
+
14
+ def test_plus()
15
+ assert_equal("1test", 1 + "test")
16
+ assert_equal("0test", 0 + 0 + "test")
17
+ assert_equal("125test", 124 + 1 + "test")
18
+ 20.times do
19
+ i, j = rand(0..4294967295), rand(0..4294967295)
20
+ assert_equal(i + j, j + i)
21
+ end
22
+ end
23
+
24
+ end
data/test/test_numeric.rb CHANGED
@@ -26,6 +26,7 @@ class NumericHelperTest < Minitest::Test
26
26
  assert_equal(-1, (-1).max(0))
27
27
  assert_equal(0, 0.max(1))
28
28
  assert_equal(1, (2.2).max(1))
29
+ assert_equal(20, 100.max(20))
29
30
  end
30
31
 
31
32
  def test_odd?
data/test/test_string.rb CHANGED
@@ -4,89 +4,124 @@ require_relative '../lib/rubyhelper'
4
4
 
5
5
  class StringHelperTest < Minitest::Test
6
6
 
7
+ def test_utf8
8
+ assert_raises ArgumentError do
9
+ assert_equal('r'.utf8(1))
10
+ end
11
+ end
12
+
13
+ def test_utf8
14
+ assert_equal('bonjour', 'bonjour'.utf8)
15
+ end
16
+
7
17
  def test_to_plain
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)
18
+ assert_equal('bonjour', 'bonjour'.to_plain)
19
+ assert_equal('bonjoure', 'bonjouré'.to_plain, 'bonjoure')
20
+ assert_equal('bonjo\\AAAur', 'bonjo\\AAAur'.to_plain)
21
+ assert_equal('bonjo', 'bonjo€'.to_plain)
12
22
  end
13
23
 
14
24
  def test_p
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)
25
+ assert_equal('bonjour', 'bonjour'.p)
26
+ assert_equal('bonjoure', 'bonjouré'.p)
27
+ assert_equal('bonjo\\AAAur', 'bonjo\\AAAur'.p)
28
+ assert_equal('bonjo€', 'bonjo€'.p)
19
29
  end
20
30
 
21
31
  def test_to_case_downcase
22
- assert_equal("bonjour", "bonJoUr".to_case(:downcase))
23
- assert_equal("bonjour toi", "bonJoUr tOI".to_case(:downcase))
32
+ assert_equal('bonjour', 'bonJoUr'.to_case(:downcase))
33
+ assert_equal('bonjour toi', 'bonJoUr tOI'.to_case(:downcase))
24
34
  end
25
35
 
26
36
  def test_to_case_upcase
27
- assert_equal("BONJOUR", "bonJoUr".to_case(:upcase))
28
- assert_equal("BONJOUR TOI", "bonJoUr tOI".to_case(:upcase))
37
+ assert_equal('BONJOUR', 'bonJoUr'.to_case(:upcase))
38
+ assert_equal('BONJOUR TOI', 'bonJoUr tOI'.to_case(:upcase))
29
39
  end
30
40
 
31
41
  def test_to_case_capitalize
32
- assert_equal("Bonjour", "bonJoUr".to_case(:capitalize))
33
- assert_equal("Bonjour Toi", "bonJoUr tOI".to_case(:capitalize))
42
+ assert_equal('Bonjour', 'bonJoUr'.to_case(:capitalize))
43
+ assert_equal('Bonjour Toi', 'bonJoUr tOI'.to_case(:capitalize))
34
44
  end
35
45
 
36
46
  def test_to_case_classic
37
- assert_equal("Bonjour", "bonJoUr".to_case(:classic))
38
- assert_equal("Bonjour toi", "bonJoUr tOI".to_case(:classic))
47
+ assert_equal('Bonjour', 'bonJoUr'.to_case(:classic))
48
+ assert_equal('Bonjour toi', 'bonJoUr tOI'.to_case(:classic))
39
49
  end
40
50
 
41
51
  def test_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("."))
47
- end
48
-
49
- def test_static
50
- assert_equal("r", "bonjour".static(1, " "))
51
- assert_equal("our", "bonjour".static(3, " "))
52
- assert_equal("bonjour ", "bonjour".static(10, " "))
53
- assert_equal("b", "bonjour".static(1, " ", :front))
54
- assert_equal("bon", "bonjour".static(3, " ", :front))
55
- assert_equal(" bonjour", "bonjour".static(10, " ", :front))
56
- assert_equal("j", "bonjour".static(1, " ", :center))
57
- assert_equal("jo", "bonjour".static(2, " ", :center))
58
- assert_equal("njo", "bonjour".static(3, " ", :center))
59
- assert_equal("njou", "bonjour".static(4, " ", :center))
60
- assert_equal("bonjour ", "bonjour".static(8, " ", :center))
61
- assert_equal(" bonjour ", "bonjour".static(9, " ", :center))
62
- assert_equal(" bonjour ", "bonjour".static(10, " ", :center))
63
- assert_equal(" bonjour ", "bonjour".static(11, " ", :center))
52
+ assert_equal('bonjoure', 'bonjoure'.to_ascii(''))
53
+ assert_equal('bonjoure', 'bonjouré'.to_ascii(''))
54
+ assert_equal('bonjoure', 'bonjouré'.to_ascii('.'))
55
+ assert_equal('bonjour', 'bonjour€'.to_ascii(''))
56
+ assert_equal('bonjour.', 'bonjour€'.to_ascii('.'))
57
+ end
58
+
59
+ def test_static_default_params
60
+ assert_equal('bonjour'.static(1), 'bonjour'.static(1, ' ', :back))
61
+ end
62
+
63
+ def test_static_replace_param
64
+ assert_equal('bonjour---', 'bonjour'.static(10, '-', :back))
64
65
  end
65
66
 
67
+ def test_static_back
68
+ assert_equal('r', 'bonjour'.static(1, ' ', :back))
69
+ assert_equal('our', 'bonjour'.static(3, ' ', :back))
70
+ assert_equal('bonjour ', 'bonjour'.static(10, ' ', :back))
71
+ end
72
+
73
+ def test_static_front
74
+ assert_equal('b', 'bonjour'.static(1, ' ', :front))
75
+ assert_equal('bon', 'bonjour'.static(3, ' ', :front))
76
+ assert_equal(' bonjour', 'bonjour'.static(10, ' ', :front))
77
+ end
78
+
79
+ def test_static_center
80
+ assert_equal('j', 'bonjour'.static(1, ' ', :center))
81
+ assert_equal('jo', 'bonjour'.static(2, ' ', :center))
82
+ assert_equal('njo', 'bonjour'.static(3, ' ', :center))
83
+ assert_equal('njou', 'bonjour'.static(4, ' ', :center))
84
+ assert_equal('bonjour ', 'bonjour'.static(8, ' ', :center))
85
+ assert_equal(' bonjour ', 'bonjour'.static(9, ' ', :center))
86
+ assert_equal(' bonjour ', 'bonjour'.static(10, ' ', :center))
87
+ assert_equal(' bonjour ', 'bonjour'.static(11, ' ', :center))
88
+ end
89
+
90
+ def test_static_place_argument
91
+ assert_equal('r', 'bonjour'.static(1, ' ', :end))
92
+ assert_equal('r', 'bonjour'.static(1, ' ', :back))
93
+ assert_equal('r', 'bonjour'.static(1, ' ', :right))
94
+ assert_equal('j', 'bonjour'.static(1, ' ', :center))
95
+ assert_equal('j', 'bonjour'.static(1, ' ', :middle))
96
+ assert_equal('b', 'bonjour'.static(1, ' ', :begin))
97
+ assert_equal('b', 'bonjour'.static(1, ' ', :front))
98
+ assert_equal('b', 'bonjour'.static(1, ' ', :left))
99
+ end
100
+
66
101
  def test_to_t
67
- assert_equal(true, "true".to_t)
68
- assert_equal(false, "false".to_t)
69
- assert_equal(nil, "truex".to_t)
70
- assert_equal(nil, "xfalsex".to_t)
71
- assert_equal(nil, "".to_t)
102
+ assert_equal(true, 'true'.to_t)
103
+ assert_equal(false, 'false'.to_t)
104
+ assert_equal(nil, 'truex'.to_t)
105
+ assert_equal(nil, 'xfalsex'.to_t)
106
+ assert_equal(nil, ''.to_t)
72
107
  end
73
108
 
74
109
  def test_true?
75
- assert_equal(true, "true".true?)
76
- assert_equal(false, "false".true?)
77
- assert_equal(false, "other".true?)
110
+ assert_equal(true, 'true'.true?)
111
+ assert_equal(false, 'false'.true?)
112
+ assert_equal(false, 'other'.true?)
78
113
  end
79
114
 
80
115
  def test_false?
81
- assert_equal(false, "true".false?)
82
- assert_equal(true, "false".false?)
83
- assert_equal(false, "other".false?)
116
+ assert_equal(false, 'true'.false?)
117
+ assert_equal(true, 'false'.false?)
118
+ assert_equal(false, 'other'.false?)
84
119
  end
85
120
 
86
121
  def test_scapitalize
87
- assert_equal("Bonjour Monsieur", "Bonjour Monsieur".scapitalize)
88
- assert_equal("Bonjour M A D & A", "BONJOUR M A D & A".scapitalize)
89
- assert_equal("1 And 1 Sontdesvoleurs", "1 and 1 sontdesvoleurs".scapitalize)
122
+ assert_equal('Bonjour Monsieur', 'Bonjour Monsieur'.scapitalize)
123
+ assert_equal('Bonjour M A D & A', 'BONJOUR M A D & A'.scapitalize)
124
+ assert_equal('1 And 1 Sontdesvoleurs', '1 and 1 sontdesvoleurs'.scapitalize)
90
125
  end
91
126
 
92
127
  def test_splity
@@ -5,18 +5,25 @@ require_relative '../lib/rubyhelper'
5
5
  class StringNumericHelperTest < Minitest::Test
6
6
 
7
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)
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
14
  end
15
15
 
16
16
  def test_to_ii
17
17
  assert_equal(11, "1 1".to_ii())
18
18
  assert_equal(60868, "06.08.68".to_ii("."))
19
19
  assert_equal(60868, "06.08.68".to_ii("\. \t\-"))
20
+ assert_equal(0, "a6 000".to_ii(" "))
21
+ end
22
+
23
+ def test_to_ii_raise
24
+ assert_raises ArgumentError do
25
+ assert_equal(1312, '13 12 01'.get_1int(true, 1))
26
+ end
20
27
  end
21
28
 
22
29
  def test_get_int
@@ -29,24 +36,32 @@ class StringNumericHelperTest < Minitest::Test
29
36
  end
30
37
 
31
38
  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))
39
+ assert_equal('1312', '1312'.get_1int())
40
+ assert_equal('-13', 'ea -ze -13e12 à nnazdaz d'.get_1int())
41
+ assert_equal('13', '13ea -ze -13e12 à nnazdaz d'.get_1int())
42
+ assert_equal('13', 'ea -ze -13e12 à nnazdaz d'.get_1int(false))
43
+ assert_equal('-13', 'ea -ze -13e12 à nnazdaz d'.get_1int(:less))
44
+ assert_equal('13', 'ea -ze 13-13e12 à nnazdaz d'.get_1int(false))
45
+ assert_equal('1312', '13 12.01'.get_1int(true, ' '))
46
+ end
47
+
48
+ def test_get_1int_raise
49
+ assert_raises ArgumentError do
50
+ assert_equal('1312', '13 12.01'.get_1int(true, 124))
51
+ end
38
52
  end
39
53
 
40
54
  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('-'))
55
+ assert_equal(['1', '-3', '+12'], '1 -3 +12'.get_ints())
56
+ assert_equal(['1', '-3', '+12'], 'a1;aaa -3eze +1ez2ez'.get_ints())
57
+ assert_equal(['1', '3+12'], '1 -3 +12'.get_ints('-'))
44
58
  end
45
59
 
46
60
  def test_get_1ints
47
61
  assert_equal(["1", "-3", "+12"], "1 -3 +12".get_1ints())
48
62
  assert_equal(["1", "-3", "+1"], "a1;aaa -3eze +1ez2ez".get_1ints())
49
- assert_equal(["1", "3"], "1 -3 +12".get_1ints('-'))
63
+ assert_equal(["1", "3"], "1 -3 +12".get_1ints("-"))
64
+ assert_equal(["11", "33"], "1 1\t3 3".get_1ints("\t", true, " "))
50
65
  end
51
66
 
52
67
  def test_get_float
@@ -60,44 +75,63 @@ class StringNumericHelperTest < Minitest::Test
60
75
  end
61
76
 
62
77
  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))
78
+ assert_equal('1312.1', '1312.1'.get_1float())
79
+ assert_equal('-13,2', 'ea -ze -13,2e12,2 à nnazdaz d'.get_1float())
80
+ assert_equal('13,12', '13,12ea -ze -13,12e12,13 à nnazdaz d'.get_1float())
81
+ assert_equal('13.0', 'ea -ze -13.0e12 à nnazdaz d'.get_1float(false))
82
+ assert_equal('13.', 'ea -ze 13.-13.1e12.2 à nnazdaz d'.get_1float(false))
83
+ assert_equal('-13.1', 'ea -ze -13.1e12.2 à nnazdaz d'.get_1float(:less))
69
84
  end
70
85
 
71
86
  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('-'))
87
+ assert_equal(['1', '-3', '+12'], '1 -3 +12'.get_floats())
88
+ assert_equal(['1', '-3.1', '+12'], 'a1;aaa -3.1eze +1ez2ez'.get_floats())
89
+ assert_equal(['1', '3+12,2'], '1 -3 +12,2'.get_floats('-'))
75
90
  end
76
91
 
77
92
  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('-'))
93
+ assert_equal(['1', '-3', '+12'], '1 -3 +12'.get_1floats())
94
+ assert_equal(['1', '-3.1', '+1'], 'a1;aaa -3.1eze +1ez2ez'.get_1floats())
95
+ assert_equal(['1', '3,1'], '1 -3,1 +12,2'.get_1floats('-'))
81
96
  end
82
97
 
83
98
  def test_ha2m2
84
99
  #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)
100
+ assert_equal(10_000.0, '1 ha'.ha2m2)
101
+ assert_equal(10_000.0, '1 Ha'.ha2m2)
102
+ assert_equal(10_000.0, 'ha 1'.ha2m2)
103
+ assert_equal(10_000.0, '1ha'.ha2m2)
89
104
 
90
105
  #advanced match
91
- assert_equal(12000, "1.2 Ha".ha2m2)
92
- assert_equal(12000, " 1,200 Ha".ha2m2)
106
+ assert_equal(12000, '1.2 Ha'.ha2m2)
107
+ assert_equal(12000, ' 1,200 Ha'.ha2m2)
108
+ assert_equal(10000.0, '1 ha (+ 10 m²)'.ha2m2)
109
+ assert_equal(10000.0, '1 ha (+ 10 m2)'.ha2m2)
93
110
 
94
111
  #not match
95
- assert_equal(1.0, "1 m2".ha2m2)
96
- assert_equal(1.0, "1 h a".ha2m2)
112
+ assert_equal(1.0, '1 m2'.ha2m2)
113
+ assert_equal(1.0, '1 h a'.ha2m2)
97
114
 
98
115
  #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)
116
+ assert_equal(1.0, '1 m2 (+ 1 ha)'.ha2m2)
117
+ assert_equal(50.0, '50.0 m² without the 1 ha of eastead'.ha2m2)
118
+ end
119
+
120
+ def test_plus
121
+ assert_equal("test1", "test" + 1)
122
+ assert_equal("test0", "test" + 0)
123
+ assert_equal("test00", "test" + 0 + 0)
124
+ assert_equal("test1241", "test" + 124 + 1)
125
+ assert_equal("test125", "test" + (124 + 1))
126
+ 20.times do
127
+ i = rand(0..4294967295)
128
+ assert_equal("test#{i}", "test" + i)
129
+ end
130
+ end
131
+
132
+ # use also #{Fixnum#+}
133
+ def test_plus_hybrid
134
+ assert_equal("test1test", "test" + 1 + "test")
101
135
  end
102
136
 
103
137
  end
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -31,27 +31,27 @@ cert_chain:
31
31
  +lG6tRo8QaFrH3afOmy4VUaG84Jm1XjNYnyaOfLb9ItpcQgVySn2c3aJ2PLcPljM
32
32
  EhZUryAiV8KNMQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-09-12 00:00:00.000000000 Z
34
+ date: 2014-09-30 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:
38
38
  - poulet_a@epitech.eu
39
39
  - - lib/rubyhelper.rb
40
- - lib/rubyhelper/gem-version.rb
40
+ - lib/gem-version.rb
41
41
  - lib/rubyhelper/string.rb
42
42
  - lib/rubyhelper/string_numeric.rb
43
43
  - lib/rubyhelper/array.rb
44
44
  - lib/rubyhelper/numeric.rb
45
- - lib/rubyhelper/integer.rb
45
+ - lib/rubyhelper/fixnum.rb
46
46
  - lib/rubyhelper/time.rb
47
47
  - lib/rubyhelper/hash.rb
48
- - lib/rubyhelper/argumenterror.rb
49
48
  - README.md
50
49
  - Rakefile
51
50
  - rubyhelper.gemspec
52
51
  - test/test_array.rb
53
52
  - test/test_hash.rb
54
53
  - test/test_numeric.rb
54
+ - test/test_fixnum.rb
55
55
  - test/test_string.rb
56
56
  - test/test_string_numeric.rb
57
57
  executables: []
@@ -60,18 +60,18 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - README.md
62
62
  - Rakefile
63
+ - lib/gem-version.rb
63
64
  - lib/rubyhelper.rb
64
- - lib/rubyhelper/argumenterror.rb
65
65
  - lib/rubyhelper/array.rb
66
- - lib/rubyhelper/gem-version.rb
66
+ - lib/rubyhelper/fixnum.rb
67
67
  - lib/rubyhelper/hash.rb
68
- - lib/rubyhelper/integer.rb
69
68
  - lib/rubyhelper/numeric.rb
70
69
  - lib/rubyhelper/string.rb
71
70
  - lib/rubyhelper/string_numeric.rb
72
71
  - lib/rubyhelper/time.rb
73
72
  - rubyhelper.gemspec
74
73
  - test/test_array.rb
74
+ - test/test_fixnum.rb
75
75
  - test/test_hash.rb
76
76
  - test/test_numeric.rb
77
77
  - test/test_string.rb
@@ -99,6 +99,6 @@ rubyforge_project:
99
99
  rubygems_version: 2.4.1
100
100
  signing_key:
101
101
  specification_version: 4
102
- summary: Improvements and additions by poulet_a to the basic ruby classes
102
+ summary: See Changelog
103
103
  test_files: []
104
104
  has_rdoc:
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- IWZ&�k�Jplr�!��.M%�Z ��O��\'�<�m]F�O���>'�R��&U���
1
+ n�S�����Ƞ�6�kM�����`gَ�/��۬^��c����Q�I���q����������N�h�L�����R�k�MU{��У ��鉧g�%i���.���4��^,Kj����:��/*��me҅���
2
+ FP��JؒA�&D��E�7�
@@ -1,9 +0,0 @@
1
- #encoding: utf-8
2
-
3
- class ArgumentError
4
-
5
- def self.force_type(var, type, name='argument')
6
- raise ArgumentError, "#{name} must be a #{type}" unless var.is_a? type
7
- end
8
-
9
- end
@@ -1,3 +0,0 @@
1
- module RubyHelper
2
- VERSION = '1.3.0'
3
- end
@@ -1,17 +0,0 @@
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