rubyhelper 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6851b40a4cf69a6d0a3754db488f38a3e5f7938
4
- data.tar.gz: 53db33d7c1fa2860abdf3f63c3561f92d93872f4
3
+ metadata.gz: 6242a9c09772908bd881caa26336e4120863798b
4
+ data.tar.gz: 86964bfc7655e99f129dd20d7cf468235ff1ba6e
5
5
  SHA512:
6
- metadata.gz: c6cc4317fb023e6e2c0026c3fb50e7b37d56d13242fb27337fc9f4bba49dbf63ae2614d3d21a1b40c9a83ef415b3dff853633191798d902b925b1aa2d405c354
7
- data.tar.gz: e7ff30b52e7a1f85692993e871359c533b5dc9d87a1ecfd10345d6242cfb0bd96675fd05d2a2e8a1f12441c33eae7eb3fe285cf166f6d898b296e9234eecf553
6
+ metadata.gz: cfb803191d145419ff2ce8c14a68eb8eeb5f9ad044b72b41d8fa2326603b5000671b90c7a09f3b336a6907fe5dcb6dfc812c97579fbe79a3f77c97ac5bb467ae
7
+ data.tar.gz: 5664d87ecbc59fd7312574231cfe623d11907b62200427db000d834fb750389bebfde43139e2f0bbe4d0077692f00f963194ab8b908962be9a6ef1b3b7c151bb
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -39,15 +39,16 @@ in this gem ;)
39
39
  The following sources code is not only my stuff, but also an implementation of
40
40
  idea found on stackoverflow, ...
41
41
 
42
- The developpement running like that :
43
- 1. Found idea
44
- 2. Put it in the gem
45
- 3. Developpe few tests
46
- 4. Push it in a unstable gem (like v1.0.alpha1)
47
- 5. **repeat 1-4 actions few times**
48
- 6. Improve tests
49
- 7. Validate the version
50
- 8. Push new "stable" version (like v1.1)
42
+ The developpement running like that :
43
+ 1. Found idea
44
+ 2. Put it in the gem
45
+ 3. Developpe few tests
46
+ 4. Push it in a unstable gem (like v1.0.alpha1)
47
+ 5. **repeat 1-4 actions few times**
48
+ 6. Improve tests
49
+ 7. Validate the version
50
+ 8. Push the version into master branch and tag it
51
+ 9. Push new "stable" version (like v1.1)
51
52
 
52
53
  Note about the first time developpement :
53
54
  I didn't predict to keep this gem in dev so the first part of the dev
@@ -5,12 +5,10 @@ module ArrayHelper
5
5
  # This function return a pretty good string. Like join but with an array
6
6
  # You can use an array as separator : [",", " "] will successively ',' and ' '
7
7
  # Exemple : ["a", "b", "c"].joini(["x", "y"]) => "axbyc"
8
- # == Errors:
9
- # - ArgumentError : if sep in not an array
10
- # == Params:
11
- # - sep: (Array) array of separator
12
- # == Returns:
13
- # - str: (String) string joined
8
+ #
9
+ # @raise [ArgumentError] if sep in not an array
10
+ # @param sep [Array] array of separator
11
+ # @return [String] string joined
14
12
  def joini sep
15
13
  raise ArgumentError, 'Argument is not an array' unless sep.is_a? Array
16
14
  str = String.new
@@ -25,47 +23,38 @@ module ArrayHelper
25
23
  # Do the sum of an array of integer.
26
24
  # if there is not integer, it will do a to_s.to_i of the element to try
27
25
  # find an integer in the element. else, replace by a simple 0
28
- # == Params:
29
- # none
30
- # == Returns:
31
- # sum: (Integer) the sum of each element (converted via .to_s.to_i)
26
+ #
27
+ # @return [Integer] the sum of each element (converted via .to_s.to_i)
32
28
  def sum
33
29
  return (self.size > 0) ? (self.map{|e| e.to_s.to_i}.reduce(:+)) : (0)
34
30
  end
35
31
 
36
32
  # lke sum by with a to_f instead of to_i
37
- # == Params:
38
- # none
39
- # == Returns:
40
- # sum: (Float) the sum of each element (converted via .to_s.to_f)
33
+ #
34
+ # @return [Float] the sum of each element (converted via .to_s.to_f)
41
35
  def sumf
42
36
  return (self.size > 0) ? (self.map{|e| e.to_s.to_f}.reduce(:+)) : (0.0)
43
37
  end
44
38
 
45
39
  # Use the sum and divide by the size of the array.
46
- # == Params:
47
- # none
48
- # == Returns:
49
- # average: (Integer) self.sum / self.size. 0 if no elements
40
+ #
41
+ # @return [Integer] self.sum / self.size. 0 if no elements
50
42
  def average
51
43
  return (self.size > 0) ? (self.sum / self.size) : (0)
52
44
  end
53
45
 
54
46
  # Same than average but use to_f instead of to_i
55
- # == Params:
56
- # none
57
- # == Returns:
58
- # average: (Float) self.sumf / self.size. 0.0 if no elements
47
+ #
48
+ # @return [Float] self.sumf / self.size. 0.0 if no elements
59
49
  def averagef
60
50
  return (self.size > 0) ? (self.sumf / self.size.to_f) : (0.0)
61
51
  end
62
52
 
63
53
  # get the n higher values of the array
64
- # == Errors:
65
- # - ArgumentError : if n in not an integer
66
- # - ArgumentError : if n is lesser than 1
67
- # == Params:
68
- # - n: (Integer) number of elements
54
+ #
55
+ # @raise [ArgumentError] if n in not an integer
56
+ # @raise [ArgumentError] if n is lesser than 1
57
+ # @param n [Integer] number of elements
69
58
  def maxs(n=1)
70
59
  raise ArgumentError, 'Argument is not an integer' unless n.is_a? Integer
71
60
  raise ArgumentError, 'Argument is lesser than 1' unless n >= 1
@@ -74,11 +63,10 @@ module ArrayHelper
74
63
  end
75
64
 
76
65
  # get the n lower values of the array
77
- # == Errors:
78
- # - ArgumentError : if n in not an integer
79
- # - ArgumentError : if n is lesser than 1
80
- # == Params:
81
- # - n: (Integer) number of elements
66
+ #
67
+ # @raise [ArgumentError] if n in not an integer
68
+ # @raise [ArgumentError] if n is lesser than 1
69
+ # @param n [Integer] number of elements
82
70
  def mins(n=1)
83
71
  raise ArgumentError, 'Argument is not an integer' unless n.is_a? Integer
84
72
  raise ArgumentError, 'Argument is lesser than 1' unless n >= 1
@@ -89,15 +77,15 @@ module ArrayHelper
89
77
 
90
78
  # The Same as compact but remove empty string too
91
79
  # see #compact
92
- # == Params:
93
- # none
94
- # == Returns:
95
- # compacti: (Array) compacted array
80
+ #
81
+ # @return [Array] compacted array
96
82
  def compacti
97
83
  return self.map{|e| e == "" ? nil : e}.compact
98
84
  end
99
85
 
100
- # see #compacti
86
+ # see {#compacti}
87
+ #
88
+ # @return [Array]
101
89
  def compacti!
102
90
  return self.replace(self.compacti)
103
91
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHelper
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -1,11 +1,15 @@
1
1
  module HashHelper
2
2
 
3
3
  # Return a hash that includes everything but the given keys.
4
+ #
5
+ # @return [Hash]
4
6
  def except(*keys)
5
7
  return self.dup.except!(*keys)
6
8
  end
7
9
 
8
10
  # Replaces the hash without the given keys.
11
+ #
12
+ # @return [Hash]
9
13
  def except!(*keys)
10
14
  keys.each { |key| self.delete(key) }
11
15
  return self
@@ -4,36 +4,42 @@
4
4
  module NumericHelper
5
5
 
6
6
  # get - or + function of the sign of the integer
7
- # == Params:
8
- # none
9
- # == Returns:
10
- # none
11
- def sign
12
- return (self < 0) ? ("-") : ("+")
7
+ #
8
+ # @param plus [Object] a value if self >= 0
9
+ # @param less [Object] a value if self < 0
10
+ # @return [Object] the param plus or less if self >= 0 or < 0
11
+ def sign(plus="+", less="-")
12
+ return (self < 0) ? (less) : (plus)
13
13
  end
14
14
 
15
15
  # Get the self value or minimum_value if greater than self
16
- # == Errors:
17
- # - ArgumentError : if the passed value is not an integer
18
- # == Returns:
19
- # - value: (Numeric) self if self >= min else min
16
+ #
17
+ # @raise [ArgumentError] if the passed value is not an integer
18
+ # @return [Numeric] self if self >= min else min
20
19
  def min(minimum_value)
21
20
  raise ArgumentError unless minimum_value.is_a? Numeric
22
21
  return self >= minimum_value ? self : minimum_value
23
22
  end
23
+
24
+ # see {#min}
25
+ #
26
+ # @return [Numeric]
24
27
  def min!(minimum_value)
25
28
  return self.replace(self.min(minimum_value))
26
29
  end
27
30
 
28
31
  # Get the self value or maximum_value if lesser than self
29
- # == Errors:
30
- # - ArgumentError : if the passed value is not an integer
31
- # == Returns:
32
- # - value: (Numeric) self if self <= max else max
32
+ #
33
+ # @raise [ArgumentError] if the passed value is not an integer
34
+ # @return [Numeric] self if self <= max else max
33
35
  def max(maximum_value)
34
36
  raise ArgumentError unless maximum_value.is_a? Numeric
35
37
  return self <= maximum_value ? self : maximum_value
36
38
  end
39
+
40
+ # see {#max}
41
+ #
42
+ # @return [Numeric]
37
43
  def max!(maximum_value)
38
44
  return self.replace(self.min(maximum_value))
39
45
  end
@@ -6,15 +6,16 @@ require 'digest'
6
6
  module StringHelper
7
7
 
8
8
  # Force utf-8 encoding (shortcut ;) ! )
9
- # == Params:
10
- # - replace: (String) replace invalids chars by other chas
11
- # == Returns:
12
- # - self: (String) utf-8 string
9
+ #
10
+ # @param replace [String] replace invalids chars by other chas
11
+ # @return [String] utf-8 string
13
12
  def utf8 replace=''
14
13
  return self.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace)
15
14
  end
16
15
 
17
- # see #utf8
16
+ # see {#utf8}
17
+ #
18
+ # @return [String]
18
19
  def utf8!
19
20
  return self.replace(self.utf8)
20
21
  end
@@ -22,25 +23,25 @@ module StringHelper
22
23
  # UTF-8 encoding and replace invalid chars.
23
24
  # Remove accents from the string (convert to ASCII chars !)
24
25
  # And then, change the case as first argument if not nil
25
- # == Params:
26
- # - case_mod: nil (not changement), :upcase, :capitalize or :downcase
27
- # - replace: (String) if a char is not utf8 valid, character will replace it
28
- # == Returns:
29
- # - self: (String)
26
+ #
27
+ # @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil for no case change
28
+ # @param replace [String] if a char is not utf8 valid, character will replace it
29
+ # @return [String] self changed
30
30
  def to_plain(case_mod = nil, replace='')
31
31
  return self.p(replace).utf8(replace).to_case(case_mod)
32
32
  end
33
33
 
34
- # see #to_plain
34
+ # see {#to_plain}
35
+ #
36
+ # @return [String]
35
37
  def to_plain!(case_mod = nil, replace='')
36
38
  return self.replace(self.to_plain(case_mod, replace))
37
39
  end
38
40
 
39
41
  # Remove accents from the string, and replace it by the same letter in ASCII
40
- # == Params:
41
- # - replace: (String) replace by character default case
42
- # == Returns:
43
- # - self: (String)
42
+ #
43
+ # @param replace [String] replace by character default case
44
+ # @return [String] self cahnged
44
45
  def p(replace='')
45
46
  begin
46
47
  return self.tr("ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
@@ -50,14 +51,17 @@ module StringHelper
50
51
  end
51
52
  end
52
53
 
53
- # see #p
54
+ # see {#p}
55
+ #
56
+ # @return [String]
54
57
  def p!(replace='')
55
58
  return self.replace(self.p(replace))
56
59
  end
57
60
 
58
61
  # permit to do upcase/downcase/capitalize easier with a simple param
59
- # == Params:
60
- # - case_mod: nil (not changement), :upcase, :capitalize or :downcase
62
+ #
63
+ # @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil if no case change
64
+ # @return [String] self changed
61
65
  def to_case(case_mod = :downcase)
62
66
  case case_mod
63
67
  when :upcase
@@ -71,18 +75,19 @@ module StringHelper
71
75
  end
72
76
  end
73
77
 
74
- # see #to_case
78
+ # see {#to_case}
79
+ #
80
+ # @return [String]
75
81
  def to_case!(case_mod = :downcase)
76
82
  return self.replace(self.to_case(case_mod))
77
83
  end
78
84
 
79
85
  # Return a simple ascii string. Invalid characters will be replaced by "replace" (argument)
80
86
  # Accents are removed first and replaced by the equivalent ASCII letter
81
- # == Params:
82
- # - replace: a caracter to replace non-ascii chars
83
- # - case_mod: nil (not changement), :upcase, :capitalize or :downcase
84
- # == Returns:
85
- # - self: (String)
87
+ #
88
+ # @param replace [String] a caracter to replace non-ascii chars
89
+ # @param case_mod [Symbol] :upcase, :capitalize or :downcase or nil if no case change
90
+ # @return [String] self changed
86
91
  def to_ascii(replace="", case_mod = nil)
87
92
  s = String.new
88
93
  self.p.each_char do |c|
@@ -92,28 +97,26 @@ module StringHelper
92
97
  end
93
98
 
94
99
  # improvement of to_f to count "," caracter as "."
95
- # == Params:
96
- # none
97
- # == Returns:
98
- # - float: (Float)
100
+ #
101
+ # @return [Float] like {Integer#to_f}
99
102
  def to_fi
100
103
  return self.gsub(',', '.').to_f
101
104
  end
102
105
 
103
106
  # to_i with delimiter to remove
104
107
  # Example : "12.000.000".to_ii => 12000000
105
- # == Params:
106
- # - char: char to delete (default : ' ')
107
- # == Returns:
108
- # - integer: (Integer)
109
- # == Errors:
110
- # ArgumentError: If (param char) is not a String
108
+ #
109
+ # @param char [String] char to delete (default : ' ')
110
+ # @return [Integer] like {Integer#to_i]
111
+ # @raise [ArgumentError] If (param char) is not a String
111
112
  def to_ii(char=' ')
112
113
  raise ArgumentError, "Argument is not a String" unless char.is_a? String
113
114
  self.delete(char).to_i
114
115
  end
115
116
 
116
117
  # CRYXOR (one time pad dirt application)
118
+ #
119
+ # @return [String]
117
120
  def ^(k)
118
121
  str = ""
119
122
  self.size.times do |i|
@@ -123,12 +126,16 @@ module StringHelper
123
126
  end
124
127
 
125
128
  # SHA2 shortcuts
126
- # see #Digest::SHA2.hexdigest
129
+ # see {Digest::SHA2#hexdigest}
130
+ #
131
+ # @return [String]
127
132
  def sha2
128
133
  Digest::SHA2.hexdigest(self)
129
134
  end
130
135
 
131
- # see #sha2
136
+ # see {#sha2}
137
+ #
138
+ # @return [String]
132
139
  def sha2!
133
140
  return self.replace(self.sha2)
134
141
  end
@@ -136,12 +143,12 @@ module StringHelper
136
143
  # Get a str with a static length.
137
144
  # If the str size > n, reduce the str (keep str from the (param place) )
138
145
  # You should check the test files for examples
139
- # == Params:
140
- # - n: number of char
141
- # - char: char to replace if the initial str is too short
142
- # - place: :begin/:front :end/:back :center/:middle
143
- # == Errors:
144
- # - ArgumentError : if n in not an integer/char a String
146
+ #
147
+ # @param n [Integer] number of char
148
+ # @param char [String] char to replace if the initial str is too short
149
+ # @param place [Symbol] :begin/:front :end/:back :center/:middle
150
+ # @raise [ArgumentError] if n in not an integer/char a String
151
+ # @return [String]
145
152
  def static(n, char=' ', place= :back)
146
153
  raise ArgumentError, 'char is not an Char (String)' unless char.is_a? String
147
154
  raise ArgumentError, 'n is not an Integer' unless n.is_a? Integer
@@ -170,11 +177,10 @@ module StringHelper
170
177
  return self.replace(self.static(n, char))
171
178
  end
172
179
 
173
- #Returns true or false if the string if "true" or "false". else nil
174
- # == Params:
175
- # none
176
- # == Returns:
177
- # - true/false
180
+ # Returns true or false if the string if "true" or "false". else nil
181
+ #
182
+ # @return [TrueClass]
183
+ # @return [FalseClass]
178
184
  def to_t
179
185
  case self
180
186
  when "true"
@@ -186,46 +192,48 @@ module StringHelper
186
192
  end
187
193
  end
188
194
 
189
- #get only the digits and symbols in the string
190
- # == Params:
191
- # - sign: (true/false) if true, keep the - and + signs
192
- # == Return:
193
- # epured_string: (String)
195
+ # get only the digits and symbols in the string
196
+ #
197
+ # @param sign (true/false) if true, keep the - and + signs
198
+ # @return [String] epured string
194
199
  def get_int(sign = true)
195
200
  return self.gsub(/[^\-\+\d]/, "") if sign == true
196
201
  return self.gsub(/[^\d]/, "")
197
202
  end
198
203
 
199
204
  # see #get_int
205
+ #
206
+ # @return [String]
200
207
  def get_int!(sign = true)
201
208
  return self.replace(self.get_int(sign))
202
209
  end
203
210
 
204
- #as get_int but with . and ,
205
- # == Params:
206
- # - sign: (true/false) if true, keep the - and + signs
207
- # == Returns:
208
- # epured_string: (String)
211
+ # as get_int but with . and ,
212
+ #
213
+ # @param sign (true/false) if true, keep the - and + signs
214
+ # @return [String] epured_string
209
215
  def get_float(sign = true)
210
216
  return self.gsub(/[^\-\+\d\.\,]/, "") if sign == true
211
217
  return self.gsub(/[^\d\.\,]/, "") if sign == true
212
218
  end
213
219
 
214
- # see #get_float
220
+ # see {#get_float}
221
+ #
222
+ # @return [String]
215
223
  def get_float!(sign = true)
216
224
  return self.replace(self.get_float(sign))
217
225
  end
218
226
 
219
227
  # Capitalize a sequence (each word)
220
- # == Params:
221
- # none
222
- # == Returns:
223
- # capitalized_string: (String)
228
+ #
229
+ # @return [String] capitalized_string
224
230
  def scapitalize
225
231
  return self.split.map(&:capitalize).join(' ')
226
232
  end
227
233
 
228
- # see #scapitalize
234
+ # see {#scapitalize}
235
+ #
236
+ # @return [String]
229
237
  def scapitalize!
230
238
  return self.replace(self.scapitalize)
231
239
  end
@@ -8,13 +8,12 @@ module VersionHelper
8
8
 
9
9
  attr_accessor :v
10
10
 
11
- # == Params:
12
- # - arg : list of arguments
13
- # Integer : 1234 => 1.2.3.4
14
- # String : "1.2-3" => 1.2.3
15
- # Array : like multiple arguments
16
- # multiple : each argument is converted to a number
17
- # 1,2,3 => 1.2.3
11
+ # [Integer] : 1234 => 1.2.3.4
12
+ # [String] : "1.2-3" => 1.2.3
13
+ # [Array] : like multiple arguments
14
+ # [multiple] : each argument is converted to a number 1,2,3 => 1.2.3
15
+ #
16
+ # @param arg : list of arguments
18
17
  def initialize(*arg)
19
18
  @v = []
20
19
  if arg.size == 1
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.1.1
4
+ version: 1.1.2
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-06 00:00:00.000000000 Z
34
+ date: 2014-09-07 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description: A list of utils for the basic Class of ruby.
37
37
  email:
metadata.gz.sig CHANGED
Binary file