split_into 1.1 → 1.2

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: 468575e8b7e8fe9573e7bdd423d4333c5edb67fe
4
- data.tar.gz: 66dc96a99217e1fb536b87c941d2ef1f52971276
3
+ metadata.gz: 29cfa62b45dd389f0ca59e98f57843664bb93944
4
+ data.tar.gz: 11aafb52fb8e2aa3e68b672296b1e8f96e15b20e
5
5
  SHA512:
6
- metadata.gz: 9f62b24b5b45c136ae536e8ba758c24112b2a26d850d8ca68136ec2174d0564ba53155c7e50214206a6047ccd874620ab3d84ca91828909874b8f8704e4095c7
7
- data.tar.gz: a89ad5137c0ad47ebf4bd91a8c2437786b1708298ff99850da14e8d70d13006b20bbbded98432881b566da2b8cb74a6a7551e4cdf0dc07991d7c242cc8388802
6
+ metadata.gz: c7e32bd21f3eb1f524c6dd544d4483ec13f11a6ca551e939713cb9213318fa1856d6db7d2db5c7371fe821fb7cdfee061201e5a8b9af2a4dfc39d75a375d1640
7
+ data.tar.gz: 7a467d6e6f5a27c4c990519feaff87b6a56b24f31d163b9129a0afd4cfeefdd5c0f345625cc5002eca2075656cc0355efcc1764e6b723a53f33b2d5d1cacdb14
data/README.md CHANGED
@@ -6,11 +6,11 @@ SplitInto is a micro API whose sole purpose is to split an integer into equal or
6
6
 
7
7
  For instance 8 cents can not be split into 3 parts equally due to the lack of 1/2 cent coins, but can be split into roughly equal parts of 2c, 3c and 3c. Using SplitInto this would be written as:
8
8
 
9
- SplitInto.split(8,3) # => [2, 3, 3]
9
+ SplitInto.split(8,3) # [2, 3, 3]
10
10
 
11
11
  9 cents can be split equally
12
12
 
13
- SplitInto.split(9,3) # => [3, 3, 3]
13
+ SplitInto.split(9,3) # [3, 3, 3]
14
14
 
15
15
  The part components will never differ by more than 1.
16
16
 
@@ -28,15 +28,26 @@ As a standalone module:
28
28
 
29
29
  require 'split_into'
30
30
 
31
- SplitInto.split(10,4)
31
+ SplitInto.split(8,4) # [2, 2, 2, 2]
32
32
 
33
- To extend integer include `split_into/extend_integer`.
33
+ To extend integer require `split_into/extend_integer`.
34
34
 
35
35
  require 'split_into/extend_integer'
36
36
 
37
- 10.split_into(4)
37
+ 10.split_into(4) # [2, 2, 3, 3]
38
+
39
+ If an integer can not be split a `SplitInto::SplitError` exception is raised.
40
+
41
+ begin
42
+ SplitInto.split(10,-2)
43
+ rescue SplitInto::SplitError => exception
44
+ puts exception.message # 'Divisor is less than zero'
45
+ end
38
46
 
39
47
  ## License
40
48
 
41
- SplitInto is distributed under the BSD License.
49
+ SplitInto is distributed under the BSD License. See LICENSE file for details.
50
+
51
+ ## Copyright
42
52
 
53
+ 2014 Aimred CC. All rights reserved.
@@ -2,7 +2,7 @@ require 'simplecheck'
2
2
  require 'split_into/split_error'
3
3
 
4
4
  module SplitInto
5
- class <<self
5
+ class << self
6
6
  include Simplecheck
7
7
  end
8
8
 
@@ -12,8 +12,8 @@ module SplitInto
12
12
  check(divisor <= dividend, error_message: 'Divisor is greater than the dividend')
13
13
 
14
14
  return [] if divisor.zero?
15
-
16
- parts = Array.new(divisor){ dividend.div(divisor) }
15
+
16
+ parts = Array.new(divisor, dividend.div(divisor))
17
17
  dividend.modulo(divisor).times { |i| parts[i] += 1 }
18
18
  parts.reverse
19
19
  rescue Simplecheck::CheckFailed => exception
@@ -1,3 +1,3 @@
1
1
  module SplitInto
2
- VERSION = '1.1'
2
+ VERSION = '1.2'
3
3
  end
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.name = 'split_into'
6
6
  s.version = SplitInto::VERSION
7
7
  s.licenses = ['BSD']
8
- s.summary = "Split an integer into equally sized component integers"
8
+ s.summary = "Split an integer into equal or roughly equal sized component integers"
9
9
  s.description = "SplitInto is a micro API whose sole purpose is to split an integer into equal or roughly equal parts. This is useful when dealing with objects that are not well suited to being split into fractional parts."
10
10
  s.author = "Farrel Lifson"
11
11
  s.email = 'farrel.lifson@aimred.com'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split_into
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Farrel Lifson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecheck
@@ -68,7 +68,7 @@ rubyforge_project:
68
68
  rubygems_version: 2.2.0
69
69
  signing_key:
70
70
  specification_version: 4
71
- summary: Split an integer into equally sized component integers
71
+ summary: Split an integer into equal or roughly equal sized component integers
72
72
  test_files:
73
73
  - test/split_into_extend_integer_test.rb
74
74
  - test/split_into_test.rb