rubyhelper 1.2.alpha4 → 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: 05ffe2c5c0a58b713e88bed0da93ef7fa9c70089
4
- data.tar.gz: 77d379e1f9aa30492c732b7071c1a7e3f9345ff8
3
+ metadata.gz: d4e58cb59cdb152910ebf674ca688c14e4b7792a
4
+ data.tar.gz: 2bd48c17e6dab1b72d1ac7daaded868a22d1cea3
5
5
  SHA512:
6
- metadata.gz: 90ad32b9aeb04d6bc9c24968d0f6d0e35718d05fe3e3f565284a42a57cb9d6d2dd51d064d9230a3e1e41342322d52d08e9d0b5dc9e36f70799df9ddad254c3d8
7
- data.tar.gz: b4b17b5381d554c56c4c2d5760ddb0e31554902eacbb93372cfd0cf3d7751579e87da693bc5e32b91d474ef50366b75edcc5d9954b320099fe5b7562996708dd
6
+ metadata.gz: 4a293a8356d6e87ffb252362f9cd6cfa0ca06ab1b0e513fa19ce31100468474a38b7d27795ffb129095b24a6ac16f6fbc5145143b1c22c0637a00a6e54010939
7
+ data.tar.gz: a98e864588d151d2c606779d02825e7dff292bdb46bc544f30732c58dbfd58da67765c74818cdb865b8ae65410416ab142effb8998e73851c499db5ca599f3d2
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- �������=���ӘrdRx��=�a�jY��˷�Y�#m2��~,R�ל�m�ޔ�� tF���3;���_��fb�<����!�E��GG}+���n�\a5\�*���[�Cݟ`����b�wk��8�ݩ�� ��|$C�����L~��C=��a��Ru�)��
2
- }���}ӻ�'�]S1iz�=:(Sc0M�l ��Ou�P���ݺ����0���^��_ixzk3�T��M3�%4�`JN,��{�P��뺇�Z�l�
1
+ I:�c��I��z1���i7��v��C�9=�$JN�;1�@X�I��E��{�"2����g��B����I"/4Z��ti��� W�&�7,|m��%)���jFA���g���{ � �]���9Z[C�?6Ja�F*��n/�E����-b"%1��ʫ ��ʼnk4�>�#g?�^�oժ�t�@#D+�!=�!����@%$�@_ڦf7�.���6D'�g5ӟx�����b ��ۏ7�<�G{"� �u~[��5{D
data/README.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # rubyhelper
2
2
 
3
- Last Stable Gem [![Gem Version](https://badge.fury.io/rb/rubyhelper.svg)](http://badge.fury.io/rb/rubyhelper)
3
+ Last Stable Gem
4
+ [![Gem Version](https://badge.fury.io/rb/rubyhelper.svg)](http://badge.fury.io/rb/rubyhelper)
4
5
 
5
- - Last release v1.1 => see the branch #master
6
- - Last dev v1.2 => see the branch #dev
6
+ Last release **v1.1** ===> see the branch **#master**
7
+ Last develop **v1.2** ===> see the branch **#dev**
7
8
 
8
9
  You can see the documentation here : http://rubydoc.info/gems/rubyhelper
9
10
  The source code is available here : https://gitlab.com/poulet_a/rubyhelper
10
11
 
11
12
 
12
13
  ## How is it works ?
13
- See the [wtf] section too know what is exactly this stuff.
14
+ See the **[wtf]** section too know what is exactly this stuff.
14
15
  Too use the gem, install it :
15
16
  ```bash
16
17
  $ gem install rubyhelper # install the last stable version
@@ -30,14 +31,14 @@ in this gem ;)
30
31
 
31
32
 
32
33
  ## My favorites functions from this gem
33
- - String.new.static(n) => String
34
- Render a cool string with a static size. Few cool options tested and validated
35
- - String.new.get_float => String
36
- Usefull to extract a Numerical value from a stupid String
37
- - Array.new.average /averagef
38
- Simple and usefull integer/float average
39
- - Array.new.sumf / sum
40
- Simple and usefull float/integer sum
34
+ - **String.new.static(n)** => String
35
+ Render a cool string with a static size. Few cool options tested and validated
36
+ - **String.new.get_float** => String
37
+ Usefull to extract a Numerical value from a stupid String
38
+ - **Array.new.average** => => Numerical
39
+ Simple and usefull integer average (*averagef for Float version*)
40
+ - **Array.new.sum** => Integer
41
+ Simple and usefull integer sum (*sumf for Float version*)
41
42
 
42
43
 
43
44
  ## Notes about the source code
@@ -45,15 +46,15 @@ The following sources code is not only my stuff, but also an implementation of
45
46
  idea found on stackoverflow, ...
46
47
 
47
48
  The developpement running like that :
48
- 1. Found idea
49
- 2. Put it in the gem
50
- 3. Developpe few tests
51
- 4. Push it in a unstable gem (like v1.0.alpha1)
49
+ 1. Found idea or a bug
50
+ 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*)
52
53
  5. **repeat 1-4 actions few times**
53
- 6. Improve tests
54
- 7. Validate the version
55
- 8. Push the version into master branch and tag it
56
- 9. Push new "stable" version (like v1.1)
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*)
57
58
 
58
59
  Note about the first time developpement :
59
60
  I didn't predict to keep this gem in dev so the first part of the dev
@@ -78,4 +79,3 @@ is a little messy. Don't look back 1.1 ;)
78
79
  # Contributors
79
80
  - poulet_a : Creator and main developper. Feel free to ask me a question by email.
80
81
  email : arthur.poulet AT cryptolab.net [OpenPGP : 0x6D9EA34A]
81
-
@@ -0,0 +1,9 @@
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
@@ -6,18 +6,24 @@ module ArrayHelper
6
6
  # You can use an array as separator : [",", " "] will successively ',' and ' '
7
7
  # Exemple : ["a", "b", "c"].joini(["x", "y"]) => "axbyc"
8
8
  #
9
- # @raise [ArgumentError] if sep in not an array
10
- # @param sep [Array] array of separator
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})
11
12
  # @return [String] string joined
12
13
  def joini sep
13
- raise ArgumentError, 'Argument is not an array' unless sep.is_a? Array
14
- str = String.new
15
- i = 0
16
- self.each do |e|
17
- str = str + e.to_s + sep[i % sep.size].to_s
18
- i += 1
14
+ if sep.is_a? Array
15
+ str = String.new
16
+ i = 0
17
+ self.each do |e|
18
+ str = str + e.to_s + sep[i % sep.size].to_s
19
+ i += 1
20
+ end
21
+ return str[0..-2]
22
+ elsif sep.is_a? String
23
+ return self.join(sep)
24
+ else
25
+ raise ArgumentError, 'Argument is not an array or a string'
19
26
  end
20
- return str[0..-2]
21
27
  end
22
28
 
23
29
  # Do the sum of an array of integer.
@@ -104,6 +110,11 @@ module ArrayHelper
104
110
  # [:a, :b, :c, 1, 2, 3] => [[:a, 1], [:b, 2], [:c, 3]]
105
111
  # [:a, :b, :c, :d, 1, 2, 3] => [[:a, 1], [:b, 2], [:c, 3], [:d, nil]]
106
112
  # [:a, :b, :c, 1, 2, 3, 4] => [[:a, 2], [:b, 3], [:c, 4], [1, nil]]
113
+ # The array will be transformed into an array of couple ([x,y])
114
+ # with [0e, N/2e] where N/2e is the element at size/2. If the array have
115
+ # an odd number of elements, it will add a nil value at the end.
116
+ #
117
+ # @return [Array] mirrored array
107
118
  def mirror
108
119
  return self[0..(size/2+size%2-1)].zip(self[(size/2+size%2)..-1])
109
120
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHelper
2
- VERSION = '1.2.alpha4'
2
+ VERSION = '1.2'
3
3
  end
@@ -271,6 +271,24 @@ module StringHelper
271
271
  return self.replace(self.scapitalize)
272
272
  end
273
273
 
274
+ # by bakhou_r@epitech.eu
275
+ # split th string and only keep the non empty striped values
276
+ #
277
+ # @param sep [String] separator
278
+ # @return [Array]
279
+ def splity(sep = "\n")
280
+ raise ArgumentError, "sep must be a string" unless sep.is_a? String
281
+ return self.split(sep).map{|e| ((e.strip.empty?) ? (nil) : (e.strip))}.compact
282
+ end
283
+
284
+ # see {#splity}
285
+ #
286
+ # @param sep [String]
287
+ # @return [Array]
288
+ def splity!(sep)
289
+ return self.replace(self.splity(sep))
290
+ end
291
+
274
292
  end
275
293
 
276
294
  class String
data/lib/rubyhelper.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # simple extension
3
4
  require_relative 'rubyhelper/gem-version.rb'
4
5
  require_relative 'rubyhelper/string.rb'
5
6
  require_relative 'rubyhelper/array.rb'
6
7
  require_relative 'rubyhelper/numeric.rb'
7
8
  require_relative 'rubyhelper/time.rb'
8
9
  require_relative 'rubyhelper/hash.rb'
10
+
11
+ # extension advanced
12
+ require_relative 'rubyhelper/argumenterror.rb'
13
+
14
+ # new classes
9
15
  require_relative 'rubyhelper/versionhelper.rb'
data/rubyhelper.gemspec CHANGED
@@ -4,8 +4,8 @@ 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 = "First real release :) 1.1 with fix doc, fix tests, certification, ..."
8
- s.description = "A list of utils for the basic Class of ruby."
7
+ s.summary = "Improvements and additions by poulet_a to the basic ruby classes"
8
+ s.description = "Improvements and additions by poulet_a to the basic ruby classes"
9
9
  s.authors = [
10
10
  "poulet_a"
11
11
  ]
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  "lib/rubyhelper/numeric.rb",
19
19
  "lib/rubyhelper/time.rb",
20
20
  "lib/rubyhelper/hash.rb",
21
+ "lib/rubyhelper/argumenterror.rb",
21
22
  "lib/rubyhelper/versionhelper.rb",
22
23
  "README.md",
23
24
  "Rakefile",
data/test/test_array.rb CHANGED
@@ -7,6 +7,13 @@ class ArrayHelperTest < Minitest::Test
7
7
  def test_joini
8
8
  assert_equal("s,S.s", ["s","S","s"].joini([",", "."]))
9
9
  assert_equal("s,S.s.S", ["s","S","s","S"].joini([",", ".", "."]))
10
+ assert_equal("s.S.s.S", ["s","S","s","S"].joini("."))
11
+ end
12
+
13
+ def test_joini_error
14
+ assert_raises ArgumentError do
15
+ [].joini 1
16
+ end
10
17
  end
11
18
 
12
19
  def test_sum
data/test/test_hash.rb CHANGED
@@ -2,9 +2,9 @@
2
2
  require 'minitest/autorun'
3
3
  require_relative '../lib/rubyhelper'
4
4
 
5
- class ArrayHelperTest < Minitest::Test
5
+ class HashHelperTest < Minitest::Test
6
6
 
7
- def test_joini
7
+ def test_except
8
8
  assert_equal({ :data => :a, :datb => :b },
9
9
  {
10
10
  :datx => :x,
data/test/test_numeric.rb CHANGED
@@ -4,6 +4,12 @@ require_relative '../lib/rubyhelper'
4
4
 
5
5
  class NumericHelperTest < Minitest::Test
6
6
 
7
+ def test_sign
8
+ assert_equal("-", -1.sign("+", "-"))
9
+ assert_equal("+", 0.sign("+", "-"))
10
+ assert_equal("+", 1.sign("+", "-"))
11
+ end
12
+
7
13
  def test_min
8
14
  assert_equal(2, 1.min(2))
9
15
  assert_equal(1, 1.min(1))
data/test/test_string.rb CHANGED
@@ -116,4 +116,10 @@ class StringHelperTest < Minitest::Test
116
116
  assert_equal("1 And 1 Sontdesvoleurs", "1 and 1 sontdesvoleurs".scapitalize)
117
117
  end
118
118
 
119
+ def test_splity
120
+ assert_equal(["bonjour", "à", "toi"], "bonjour\nà\ntoi".splity)
121
+ assert_equal(["bonjour", "à", "toi"], "\nbonjour\n\nà\n\ntoi\n\n\r".splity)
122
+ assert_equal(["bonjour", "à", "toi"], "\nbonjour\n\nà\n\ntoi\n\n\r".splity)
123
+ end
124
+
119
125
  end
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.2.alpha4
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -31,9 +31,9 @@ cert_chain:
31
31
  +lG6tRo8QaFrH3afOmy4VUaG84Jm1XjNYnyaOfLb9ItpcQgVySn2c3aJ2PLcPljM
32
32
  EhZUryAiV8KNMQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-09-08 00:00:00.000000000 Z
34
+ date: 2014-09-09 00:00:00.000000000 Z
35
35
  dependencies: []
36
- description: A list of utils for the basic Class of ruby.
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
@@ -43,6 +43,7 @@ email:
43
43
  - lib/rubyhelper/numeric.rb
44
44
  - lib/rubyhelper/time.rb
45
45
  - lib/rubyhelper/hash.rb
46
+ - lib/rubyhelper/argumenterror.rb
46
47
  - lib/rubyhelper/versionhelper.rb
47
48
  - README.md
48
49
  - Rakefile
@@ -59,6 +60,7 @@ files:
59
60
  - README.md
60
61
  - Rakefile
61
62
  - lib/rubyhelper.rb
63
+ - lib/rubyhelper/argumenterror.rb
62
64
  - lib/rubyhelper/array.rb
63
65
  - lib/rubyhelper/gem-version.rb
64
66
  - lib/rubyhelper/hash.rb
@@ -87,14 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  version: '0'
88
90
  required_rubygems_version: !ruby/object:Gem::Requirement
89
91
  requirements:
90
- - - ">"
92
+ - - ">="
91
93
  - !ruby/object:Gem::Version
92
- version: 1.3.1
94
+ version: '0'
93
95
  requirements: []
94
96
  rubyforge_project:
95
97
  rubygems_version: 2.4.1
96
98
  signing_key:
97
99
  specification_version: 4
98
- summary: First real release :) 1.1 with fix doc, fix tests, certification, ...
100
+ summary: Improvements and additions by poulet_a to the basic ruby classes
99
101
  test_files: []
100
102
  has_rdoc:
metadata.gz.sig CHANGED
Binary file