subvisual-utils 0.3.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: 2e8becccaf7396ede4dae0b495394f830089cd0dc4b6bc422bb52d268f7929f7
4
+ data.tar.gz: 888fd5ca1b5ed5205d0997b9d2541cd5d050ec77eed9c0a10ff42b10df397f35
5
+ SHA512:
6
+ metadata.gz: d21f6ed2583a8a8f0cbaf5bd1a7fcb6bc090c4ba1ebd0bde7481bafcef20da3ae6a7d5dd8c23142ce5fb2fd77f9ca7a8d8538b79bb0e737038edf58c54cbc814
7
+ data.tar.gz: 7c5cfc76288b4aa836079650e04df7f4dcacd151e1fca0de2963ff31d186393521581355bd1236db9a8aaa78503f638b844c9d90e452bb2892d372d04a11b544
@@ -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,31 @@
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 `StringUtils.replace_at(string, index, replacement)`.
15
+
16
+
17
+ v0.2.0 - 2020-05-07
18
+ -------------------
19
+
20
+ - Added `ArrayUtils.pad_right(array, size, padding = nil)`.
21
+
22
+
23
+ v0.1.0 - 2020-05-06
24
+ -------------------
25
+
26
+ - Added `MathUtils.least_common_denominator(a,b)`.
27
+ - Added `MathUtils.greatest_common_divisor(a,b)`.
28
+
29
+
30
+ [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
31
+ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "faker", "~> 2.x"
8
+ gem "rake", "~> 12.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "rubocop", "~> 0.82.x"
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ subvisual-utils (0.3.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
@@ -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,107 @@
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
+ ### `Subvisual::StringUtils.replace_at(string, index, replacement)`
59
+
60
+ Replaces the character at a specific index in a String.
61
+
62
+ ```ruby
63
+ Subvisual::StringUtils.replace_at("Hello", 1, "a") # => "Hallo"
64
+ ```
65
+
66
+
67
+ Development
68
+ -----------
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
71
+ run `rake spec` to run the tests. You can also run `bin/console` for an
72
+ interactive prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`.
75
+ To release a new version, update the version number in `version.rb`, and then
76
+ run `bundle exec rake release`, which will create a git tag for the version,
77
+ push git commits and tags, and push the `.gem` file to
78
+ [rubygems.org](https://rubygems.org).
79
+
80
+
81
+ Contributing
82
+ ------------
83
+
84
+ Bug reports and pull requests are welcome on GitHub at
85
+ https://github.com/subvisual/ruby-utils.
86
+
87
+
88
+ License
89
+ -----
90
+
91
+ Subvisual::Utils is copyright :copy: 2020 Subvisual, Lda.
92
+
93
+ It is open-source, made available for free, and is subject to the terms in
94
+ its [license].
95
+
96
+
97
+ About
98
+ -----
99
+
100
+ Subvisual::Utils is maintained with :heart: by [Subvisual][subvisual].
101
+
102
+ [![Subvisual][subvisual-logo]][subvisual]
103
+
104
+
105
+ [license]: ./LICENSE.txt
106
+ [subvisual]: http://subvisual.com
107
+ [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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "subvisual/array_utils/pad"
4
+
5
+ module Subvisual
6
+ module ArrayUtils
7
+ extend Pad
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subvisual
4
+ module ArrayUtils
5
+ module Pad
6
+ def pad_right(array, size, padding = nil)
7
+ return array if array.size >= size
8
+
9
+ array + Array.new(size - array.size, padding)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "subvisual/string_utils/replace_at"
4
+
5
+ module Subvisual
6
+ module StringUtils
7
+ extend ReplaceAt
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subvisual
4
+ module StringUtils
5
+ module ReplaceAt
6
+ def replace_at(string, index, replacement)
7
+ string.chars.tap do |characters|
8
+ characters[index] = replacement
9
+ end.join
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subvisual
4
+ module Utils
5
+ VERSION = "0.3.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,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subvisual-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.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/string_utils.rb
36
+ - lib/subvisual/string_utils/replace_at.rb
37
+ - lib/subvisual/utils.rb
38
+ - subvisual-utils.gemspec
39
+ homepage: https://github.com/subvisual/ruby-utils
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ allowed_push_host: https://rubygems.org
44
+ homepage_uri: https://github.com/subvisual/ruby-utils
45
+ source_code_uri: https://github.com/subvisual/ruby-utils
46
+ changelog_uri: https://github.com/subvisual/ruby-utils/blob/master/CHANGELOG.md
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.4.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Collection of reusable Ruby utilities by Subvisual
66
+ test_files: []