subvisual-utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3a07b8529bb6e59849c36637e584e2a91be62712ba5236d51f7436f86a7786cf
4
+ data.tar.gz: 202942f03626ce641c95747c7d2564bbf8d9a1a68c04c7880dc1dd058c8e2392
5
+ SHA512:
6
+ metadata.gz: 68247b0c72c4c154652e167b6aac00d23ffb47a4ee0fb7da7426148815aeef59ed671c235227dd715d34e46a0ae6ae3e42b2ebf15537e9de2bb52d6a0a902d9a
7
+ data.tar.gz: e9c5ad92e8a5a096137ba121b26cd871dacc18a29de1eca667b45e971ed887d3e473b8645253191d344a43b243aa24361f86c6e262357a107aface1cc46343d0
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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
+
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,18 @@
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
+ - Added `MathUtils.least_common_denominator(a,b)`.
14
+ - Added `MathUtils.greatest_common_divisor(a,b)`.
15
+
16
+
17
+ [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
18
+ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 12.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop"
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ subvisual-utils (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.2)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ rexml (3.2.4)
18
+ rspec (3.9.0)
19
+ rspec-core (~> 3.9.0)
20
+ rspec-expectations (~> 3.9.0)
21
+ rspec-mocks (~> 3.9.0)
22
+ rspec-core (3.9.2)
23
+ rspec-support (~> 3.9.3)
24
+ rspec-expectations (3.9.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-mocks (3.9.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-support (3.9.3)
31
+ rubocop (0.82.0)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 2.0)
39
+ ruby-progressbar (1.10.1)
40
+ unicode-display_width (1.7.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ rake (~> 12.0)
47
+ rspec (~> 3.0)
48
+ rubocop
49
+ subvisual-utils!
50
+
51
+ BUNDLED WITH
52
+ 2.1.4
@@ -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
+
@@ -0,0 +1,89 @@
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::MathUtils.greatest_common_divisor(a,b)`
32
+
33
+ Computes the Greatest Common Divisor of two numbers.
34
+
35
+ ```ruby
36
+ Subvisual::MathUtils.greatest_common_divisor(48, 18) # => 6
37
+ ```
38
+
39
+
40
+ ### `Subvisual::MathUtils.least_common_denominator(a,b)`
41
+
42
+ Computes the Least Common Denominator of two numbers.
43
+
44
+ ```ruby
45
+ Subvisual::MathUtils.least_common_denominator(21, 6) # => 42
46
+ ```
47
+
48
+
49
+ Development
50
+ -----------
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
53
+ run `rake spec` to run the tests. You can also run `bin/console` for an
54
+ interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`.
57
+ To release a new version, update the version number in `version.rb`, and then
58
+ run `bundle exec rake release`, which will create a git tag for the version,
59
+ push git commits and tags, and push the `.gem` file to
60
+ [rubygems.org](https://rubygems.org).
61
+
62
+
63
+ Contributing
64
+ ------------
65
+
66
+ Bug reports and pull requests are welcome on GitHub at
67
+ https://github.com/subvisual/ruby-utils.
68
+
69
+
70
+ License
71
+ -----
72
+
73
+ Subvisual::Utils is copyright :copy: 2020 Subvisual, Lda.
74
+
75
+ It is open-source, made available for free, and is subject to the terms in
76
+ its [license].
77
+
78
+
79
+ About
80
+ -----
81
+
82
+ Subvisual::Utils is maintained with :heart: by [Subvisual][subvisual].
83
+
84
+ [![Subvisual][subvisual-logo]][subvisual]
85
+
86
+
87
+ [license]: ./LICENSE.txt
88
+ [subvisual]: http://subvisual.com
89
+ [subvisual-logo]: https://raw.githubusercontent.com/subvisual/guides/master/github/templates/logos/blue.png
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subvisual
4
+ module MathUtils
5
+ module LeastCommonDenominator
6
+ def least_common_denominator(a, b)
7
+ (a * b).abs / MathUtils.greatest_common_divisor(a, b)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subvisual
4
+ module Utils
5
+ VERSION = "0.1.0"
6
+ end
7
+ 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,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subvisual-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Costa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-06 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/math_utils.rb
31
+ - lib/subvisual/math_utils/greatest_common_divisor.rb
32
+ - lib/subvisual/math_utils/least_common_denominator.rb
33
+ - lib/subvisual/utils.rb
34
+ - subvisual-utils.gemspec
35
+ homepage: https://github.com/subvisual/ruby-utils
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org
40
+ homepage_uri: https://github.com/subvisual/ruby-utils
41
+ source_code_uri: https://github.com/subvisual/ruby-utils
42
+ changelog_uri: https://github.com/subvisual/ruby-utils/blob/master/CHANGELOG.md
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.4.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.0.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Collection of reusable Ruby utilities by Subvisual
62
+ test_files: []