romanumerals 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5ac06e5eb0a28e7a395360b07beec8393ad2b830f8cd96ef9de735846f8d7fd
4
+ data.tar.gz: 0b2947002ff049ea538473d520df45455b2c69d3e5d309ec75a3cde1e801f993
5
+ SHA512:
6
+ metadata.gz: fbc5e0a96c43aadd92300f11d3a7b397cd009d1d23b9857ec75cd73fbf7435092c0dec61c2cd19c24d311ddeef7fdf3f18c5b921539feaec1c9d27f97997cd73
7
+ data.tar.gz: ae3519940702d8b3b367fabbf78d336a8d297a7e5ee06854c0a35d84d0378454eecac6525f16ba454b16cfe68fbe092cdd88f6e80def4dc830bfcd429777b490
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: single_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Layout/HashAlignment:
16
+ EnforcedHashRocketStyle: table
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - 'spec/**/*'
21
+ - 'config/environments/*.rb'
22
+
23
+ Style/Documentation:
24
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-04-24
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 13.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rubocop', '~> 1.21'
10
+ gem 'codecov', require: false, group: :test
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ romanumerals (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ codecov (0.6.0)
11
+ simplecov (>= 0.15, < 0.22)
12
+ diff-lcs (1.5.0)
13
+ docile (1.4.0)
14
+ parallel (1.22.1)
15
+ parser (3.1.2.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.3.1)
20
+ rexml (3.2.5)
21
+ rspec (3.11.0)
22
+ rspec-core (~> 3.11.0)
23
+ rspec-expectations (~> 3.11.0)
24
+ rspec-mocks (~> 3.11.0)
25
+ rspec-core (3.11.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-expectations (3.11.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-mocks (3.11.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-support (3.11.0)
34
+ rubocop (1.28.1)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.1.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml
40
+ rubocop-ast (>= 1.17.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.17.0)
44
+ parser (>= 3.1.1.0)
45
+ ruby-progressbar (1.11.0)
46
+ simplecov (0.21.2)
47
+ docile (~> 1.1)
48
+ simplecov-html (~> 0.11)
49
+ simplecov_json_formatter (~> 0.1)
50
+ simplecov-html (0.12.3)
51
+ simplecov_json_formatter (0.1.4)
52
+ unicode-display_width (2.1.0)
53
+
54
+ PLATFORMS
55
+ x86_64-darwin-20
56
+ x86_64-linux
57
+
58
+ DEPENDENCIES
59
+ codecov
60
+ rake (~> 13.0)
61
+ romanumerals!
62
+ rspec (~> 3.0)
63
+ rubocop (~> 1.21)
64
+
65
+ BUNDLED WITH
66
+ 2.3.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 febonazzic
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Romanumerals
2
+ ![RSpec](https://github.com/febonazzic/romanumerals/actions/workflows/main.yml/badge.svg)
3
+ [![codecov](https://codecov.io/gh/febonazzic/romanumerals/branch/main/graph/badge.svg?token=3CS44P7B3J)](https://codecov.io/gh/febonazzic/romanumerals)
4
+
5
+ This gem allows you to convert arabic numbers to roman.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add romanumerals
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install romanumerals
16
+
17
+ ## Usage
18
+
19
+ Usage is very simple:
20
+
21
+ ```ruby
22
+ 10.to_roman # => "X"
23
+ 110.to_roman # => "CX"
24
+ 99.to_roman # => "XCIX"
25
+ 845.to_roman # => "DCCCXLV"
26
+ 1193.to_roman # => "MCXCIII"
27
+ 2022.to_roman # => "MMXXII"
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/febonazzic/romanumerals.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Romanumerals
4
+ module Numeric
5
+ def to_roman
6
+ return '' if zero?
7
+
8
+ decompose.each_with_object([]) do |(divider, count), result|
9
+ result <<
10
+ if count == 4
11
+ DICTIONARY[divider] + DICTIONARY[divider * 5]
12
+ else
13
+ DICTIONARY[divider] * count
14
+ end
15
+ end.join
16
+ end
17
+
18
+ private
19
+
20
+ def decompose
21
+ number = self
22
+
23
+ DICTIONARY.keys.each_with_object({}) do |divider, result|
24
+ dividers_count = number / divider
25
+
26
+ next unless dividers_count.positive?
27
+
28
+ result[divider] = dividers_count
29
+
30
+ number -= dividers_count * divider
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ class Numeric
37
+ include Romanumerals::Numeric
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Romanumerals
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'romanumerals/version'
4
+ require_relative 'romanumerals/numeric'
5
+
6
+ module Romanumerals
7
+ class Error < StandardError; end
8
+
9
+ DICTIONARY = {
10
+ 1000 => 'M',
11
+ 900 => 'CM',
12
+ 500 => 'D',
13
+ 400 => 'CD',
14
+ 100 => 'C',
15
+ 90 => 'XC',
16
+ 50 => 'L',
17
+ 40 => 'XL',
18
+ 10 => 'X',
19
+ 9 => 'IX',
20
+ 5 => 'V',
21
+ 4 => 'IV',
22
+ 1 => 'I'
23
+ }.freeze
24
+ end
@@ -0,0 +1,3 @@
1
+ module Romanumerals
2
+ VERSION: String
3
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: romanumerals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - febonazzic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - febonazzi@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/romanumerals.rb
29
+ - lib/romanumerals/numeric.rb
30
+ - lib/romanumerals/version.rb
31
+ - sig/romanumerals.rbs
32
+ homepage: https://github.com/febonazzic/romanumerals
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/febonazzic/romanumerals
37
+ source_code_uri: https://github.com/febonazzic/romanumerals
38
+ changelog_uri: https://github.com/febonazzic/romanumerals/blob/main/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.7
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: This gem allows you to convert integers to Roman numerals and vice versa.
58
+ test_files: []