subvisual-utils 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +60 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +22 -0
- data/README.md +98 -0
- data/Rakefile +8 -0
- data/lib/subvisual/array_utils.rb +9 -0
- data/lib/subvisual/array_utils/pad.rb +13 -0
- data/lib/subvisual/math_utils.rb +11 -0
- data/lib/subvisual/math_utils/greatest_common_divisor.rb +31 -0
- data/lib/subvisual/math_utils/least_common_denominator.rb +11 -0
- data/lib/subvisual/utils.rb +7 -0
- data/subvisual-utils.gemspec +30 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e06a11e616f5f329837b8446e9435f4a92ac97c479b83b71d65e47fcf087aad
|
4
|
+
data.tar.gz: c9066f71c06801f9c8eae2f97bf5f84386508ba795b17b2fd4051aa0b77d2e64
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 693ca65ca473999ba2817f7d14935175485f4bd9966d498631b6fe2e1a28b19e31622a8444dd1777daa5fc59205b9809456d3c7665425bb094818caa236a6a1e
|
7
|
+
data.tar.gz: bfaac0e139f9ed70af40ab92936b363d328f0052de008bb311d6655b7c36354779e197a8df3440925425d0451c1898d274fde5be9c034c80866fdb4344caae5b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
inherit_mode:
|
2
|
+
merge:
|
3
|
+
- Include
|
4
|
+
- Exclude
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
NewCops: enable
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
|
10
|
+
Layout/DotPosition:
|
11
|
+
EnforcedStyle: trailing
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/MultilineOperationIndentation:
|
17
|
+
EnforcedStyle: indented
|
18
|
+
|
19
|
+
Layout/MultilineMethodCallIndentation:
|
20
|
+
EnforcedStyle: indented
|
21
|
+
|
22
|
+
Layout/ParameterAlignment:
|
23
|
+
EnforcedStyle: with_fixed_indentation
|
24
|
+
|
25
|
+
Metrics/BlockLength:
|
26
|
+
Exclude:
|
27
|
+
- spec/**/*.rb
|
28
|
+
|
29
|
+
Naming/PredicateName:
|
30
|
+
ForbiddenPrefixes:
|
31
|
+
- is_
|
32
|
+
- have_
|
33
|
+
|
34
|
+
Style/ClassAndModuleChildren:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/IfUnlessModifier:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/NumericLiterals:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/SingleLineBlockParams:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/StringLiterals:
|
50
|
+
EnforcedStyle: double_quotes
|
51
|
+
|
52
|
+
Style/TrailingCommaInArguments:
|
53
|
+
EnforcedStyleForMultiline: comma
|
54
|
+
|
55
|
+
Style/TrailingCommaInArrayLiteral:
|
56
|
+
EnforcedStyleForMultiline: comma
|
57
|
+
|
58
|
+
Style/TrailingCommaInHashLiteral:
|
59
|
+
EnforcedStyleForMultiline: comma
|
60
|
+
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Changelog
|
2
|
+
=========
|
3
|
+
|
4
|
+
|
5
|
+
All notable changes to this project will be documented in this file.
|
6
|
+
|
7
|
+
The format is based on [Keep a Changelog],
|
8
|
+
and this project adheres to [Semantic Versioning].
|
9
|
+
|
10
|
+
|
11
|
+
Unreleased
|
12
|
+
----------
|
13
|
+
|
14
|
+
- Added `ArrayUtils.pad_right(array, size, padding = nil)`.
|
15
|
+
|
16
|
+
|
17
|
+
v0.1.0 - 2020-05-06
|
18
|
+
-------------------
|
19
|
+
|
20
|
+
- Added `MathUtils.least_common_denominator(a,b)`.
|
21
|
+
- Added `MathUtils.greatest_common_divisor(a,b)`.
|
22
|
+
|
23
|
+
|
24
|
+
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
|
25
|
+
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
subvisual-utils (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
concurrent-ruby (1.1.6)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
faker (2.11.0)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
i18n (1.8.2)
|
15
|
+
concurrent-ruby (~> 1.0)
|
16
|
+
jaro_winkler (1.5.4)
|
17
|
+
parallel (1.19.1)
|
18
|
+
parser (2.7.1.2)
|
19
|
+
ast (~> 2.4.0)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (12.3.3)
|
22
|
+
rexml (3.2.4)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.2)
|
28
|
+
rspec-support (~> 3.9.3)
|
29
|
+
rspec-expectations (3.9.1)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.3)
|
36
|
+
rubocop (0.82.0)
|
37
|
+
jaro_winkler (~> 1.5.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.7.0.1)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
rexml
|
42
|
+
ruby-progressbar (~> 1.7)
|
43
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
44
|
+
ruby-progressbar (1.10.1)
|
45
|
+
unicode-display_width (1.7.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
faker (~> 2.x)
|
52
|
+
rake (~> 12.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
rubocop (~> 0.82.x)
|
55
|
+
subvisual-utils!
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Subvisual, Lda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
Subvisual::Utils
|
2
|
+
================
|
3
|
+
|
4
|
+
Collection of reusable Ruby utilities. Made with :heart: by Subvisual.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "subvisual-utils"
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install subvisual-utils
|
23
|
+
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
|
28
|
+
Utilities are exposed as module methods grouped by the type of utility.
|
29
|
+
|
30
|
+
|
31
|
+
### `Subvisual::ArrayUtils.pad_right(array, size, padding = nil)`
|
32
|
+
|
33
|
+
Fills an array with some padding up to the specified size.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Subvisual::ArrayUtils.pad_right([1, 2, 3], 5, 0) # => [1, 2, 3, 0, 0]
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
### `Subvisual::MathUtils.greatest_common_divisor(a,b)`
|
41
|
+
|
42
|
+
Computes the Greatest Common Divisor of two numbers.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Subvisual::MathUtils.greatest_common_divisor(48, 18) # => 6
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
### `Subvisual::MathUtils.least_common_denominator(a,b)`
|
50
|
+
|
51
|
+
Computes the Least Common Denominator of two numbers.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Subvisual::MathUtils.least_common_denominator(21, 6) # => 42
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
Development
|
59
|
+
-----------
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
62
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
63
|
+
interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
66
|
+
To release a new version, update the version number in `version.rb`, and then
|
67
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
68
|
+
push git commits and tags, and push the `.gem` file to
|
69
|
+
[rubygems.org](https://rubygems.org).
|
70
|
+
|
71
|
+
|
72
|
+
Contributing
|
73
|
+
------------
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at
|
76
|
+
https://github.com/subvisual/ruby-utils.
|
77
|
+
|
78
|
+
|
79
|
+
License
|
80
|
+
-----
|
81
|
+
|
82
|
+
Subvisual::Utils is copyright :copy: 2020 Subvisual, Lda.
|
83
|
+
|
84
|
+
It is open-source, made available for free, and is subject to the terms in
|
85
|
+
its [license].
|
86
|
+
|
87
|
+
|
88
|
+
About
|
89
|
+
-----
|
90
|
+
|
91
|
+
Subvisual::Utils is maintained with :heart: by [Subvisual][subvisual].
|
92
|
+
|
93
|
+
[![Subvisual][subvisual-logo]][subvisual]
|
94
|
+
|
95
|
+
|
96
|
+
[license]: ./LICENSE.txt
|
97
|
+
[subvisual]: http://subvisual.com
|
98
|
+
[subvisual-logo]: https://raw.githubusercontent.com/subvisual/guides/master/github/templates/logos/blue.png
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "subvisual/math_utils/greatest_common_divisor"
|
4
|
+
require "subvisual/math_utils/least_common_denominator"
|
5
|
+
|
6
|
+
module Subvisual
|
7
|
+
module MathUtils
|
8
|
+
extend GreatestCommonDivisor
|
9
|
+
extend LeastCommonDenominator
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Subvisual
|
4
|
+
module MathUtils
|
5
|
+
module GreatestCommonDivisor
|
6
|
+
def greatest_common_divisor(a, b)
|
7
|
+
d = 0
|
8
|
+
|
9
|
+
while a.even? && b.even?
|
10
|
+
a /= 2
|
11
|
+
b /= 2
|
12
|
+
d += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
while a != b
|
16
|
+
if a.even?
|
17
|
+
a /= 2
|
18
|
+
elsif b.even?
|
19
|
+
b /= 2
|
20
|
+
elsif a > b
|
21
|
+
a = (a - b) / 2
|
22
|
+
else
|
23
|
+
b = (b - a) / 2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
2**d * a
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/subvisual/utils"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "subvisual-utils"
|
7
|
+
spec.version = Subvisual::Utils::VERSION
|
8
|
+
spec.authors = ["Pedro Costa"]
|
9
|
+
spec.email = ["pedro@subvisual.com"]
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.summary = "Collection of reusable Ruby utilities by Subvisual"
|
13
|
+
spec.homepage = "https://github.com/subvisual/ruby-utils"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/subvisual/ruby-utils"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/subvisual/ruby-utils/blob/master/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: subvisual-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro Costa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- pedro@subvisual.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".travis.yml"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- lib/subvisual/array_utils.rb
|
31
|
+
- lib/subvisual/array_utils/pad.rb
|
32
|
+
- lib/subvisual/math_utils.rb
|
33
|
+
- lib/subvisual/math_utils/greatest_common_divisor.rb
|
34
|
+
- lib/subvisual/math_utils/least_common_denominator.rb
|
35
|
+
- lib/subvisual/utils.rb
|
36
|
+
- subvisual-utils.gemspec
|
37
|
+
homepage: https://github.com/subvisual/ruby-utils
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
allowed_push_host: https://rubygems.org
|
42
|
+
homepage_uri: https://github.com/subvisual/ruby-utils
|
43
|
+
source_code_uri: https://github.com/subvisual/ruby-utils
|
44
|
+
changelog_uri: https://github.com/subvisual/ruby-utils/blob/master/CHANGELOG.md
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.4.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.0.3
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Collection of reusable Ruby utilities by Subvisual
|
64
|
+
test_files: []
|