tecla21-romanizer 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: 100f091b80901312b589c0d447990b294c5b2fcad98f20928eeeda4b9bc6cc33
4
+ data.tar.gz: cb7a94f2b2cba46f905d7d8aa0b281be692e44bc37b82b9808d759d2c0fdc0b7
5
+ SHA512:
6
+ metadata.gz: c9bb5482f74280316b2ea53c1af41a11bda6f46336559cb15e4047c4fa9e26e9e83e7ba227b0d6dae9e2004fd87c02a62b09c64b398c5a480f533a90421305c4
7
+ data.tar.gz: ccb1a4b9ebe97127661d4fc30dc8ed595520d19f78615be6f9403dacc58cb1d3fff6a330ad4dbd27ad6c616e66e50c9e8afbaaa79c8e23173778daf9adb0568e
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2025-03-18
4
+
5
+ ### Added
6
+ - Initial release of `Romanizer` gem.
7
+ - Added `to_roman` method to convert integers to Roman numerals.
8
+ - Added `to_integer` method to convert Roman numerals to integers.
9
+ - Added `valid_roman` method to validate Roman numerals.
10
+ - Basic test coverage for all methods.
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at amuatelembe@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in romanizer.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tecla 21, Prestação de serviços, (SU), 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.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 muatsoft
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,55 @@
1
+ # Romanizer
2
+
3
+ Romanizer - Convert Integers to Roman Numerals and Vice-Versa
4
+
5
+ Romanizer is a lightweight and efficient Ruby gem that provides seamless conversion between integers and Roman numerals. Whether you need to convert numbers to their Roman representations or decode Roman numerals back into integers, Romanizer makes it simple and reliable.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add romanizer
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install romanizer
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ require 'romanizer'
21
+
22
+ puts Romanizer.to_roman(2024) # => "MMXXIV"
23
+ puts Romanizer.to_roman(99) # => "XCIX"
24
+ puts Romanizer.to_roman(1) # => "I"
25
+
26
+ puts Romanizer.to_integer("MMXXIV") # => 2024
27
+ puts Romanizer.to_integer("XCIX") # => 99
28
+ puts Romanizer.to_integer("I") # => 1
29
+
30
+ puts Romanizer.valid_roman?("MMXXIV") # => true
31
+ puts Romanizer.valid_roman?("ABC") # => false
32
+ ```
33
+
34
+ Why Use Romanizer?
35
+ Simple and efficient: No unnecessary dependencies, just pure Ruby.
36
+ Well-tested: Ensures accuracy in conversions.
37
+ Great for learning and projects: Use it in CLI tools, educational software, and more.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Tecla21/romanizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Tecla21/romanizer/blob/main/CODE_OF_CONDUCT.md).
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the Romanizer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Tecla21/romanizer/blob/main/CODE_OF_CONDUCT.md).
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]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "romanizer"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Romanizer
4
+ VERSION = "0.1.0"
5
+ end
data/lib/romanizer.rb ADDED
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "romanizer/version"
4
+
5
+ module Romanizer
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ def self.to_roman(number)
9
+ raise ArgumentError, "Number must be between 1 and 3999" unless number.between?(1, 3999)
10
+
11
+ # Define the values and corresponding Roman symbols.
12
+ values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
13
+ symbols = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
14
+
15
+ # Initializes the string to store the Roman representation.
16
+ roman = ""
17
+
18
+ # Iterates over the values and corresponding Roman symbols.
19
+ values.each_with_index do |value, index|
20
+ while number >= value
21
+ # Adds the Roman symbol to the string and subtracts the value from the number.
22
+ roman += symbols[index]
23
+ number -= value
24
+ end
25
+ end
26
+ roman
27
+ end
28
+
29
+ def self.to_integer(roman)
30
+ raise ArgumentError, "Invalid Roman numeral" unless valid_roman?(roman)
31
+
32
+ # Define the values and corresponding Roman symbols.
33
+ roman_values = {
34
+ 'M' => 1000,
35
+ 'D' => 500,
36
+ 'C' => 100,
37
+ 'L' => 50,
38
+ 'X' => 10,
39
+ 'IX' => 9,
40
+ 'V' => 5,
41
+ 'IV' => 4,
42
+ 'I' => 1
43
+ }
44
+
45
+ result = 0
46
+
47
+ # Validate if the input is a valid Roman numeral
48
+ # return -1 unless self =~ /^[MDCLXVI]+$/
49
+ return -1 unless valid_roman?(roman)
50
+
51
+ # Iterates over the values and corresponding Roman symbols.
52
+ roman.chars.each_with_index do |char, index|
53
+ value = roman_values[char]
54
+
55
+ # If the next character has a greater value, subtract it.
56
+ if roman_values[roman[index + 1]] && roman_values[roman[index + 1]] > value
57
+ result -= value
58
+ else
59
+ result += value
60
+ end
61
+ end
62
+ result
63
+ end
64
+
65
+ def self.valid_roman?(roman)
66
+ !!(roman =~ /\A(M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}))\z/i)
67
+ end
68
+
69
+ end
data/sig/romanizer.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Romanizer
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Romanizer do
4
+ it "converts integers to Roman numerals" do
5
+ expect(Romanizer.to_roman(42)).to eq("XLII")
6
+ expect(Romanizer.to_roman(1994)).to eq("MCMXCIV")
7
+ expect(Romanizer.to_roman(2024)).to eq("MMXXIV")
8
+ end
9
+
10
+ it "converts Roman numerals to integers" do
11
+ expect(Romanizer.to_integer("XLII")).to eq(42)
12
+ expect(Romanizer.to_integer("MCMXCIV")).to eq(1994)
13
+ expect(Romanizer.to_integer("MMXXIV")).to eq(2024)
14
+ end
15
+
16
+ it "validates Roman numerals" do
17
+ expect(Romanizer.valid_roman?("XLII")).to be true
18
+ expect(Romanizer.valid_roman?("INVALID")).to be false
19
+ end
20
+
21
+ it "raises an error for invalid numbers" do
22
+ expect { Romanizer.to_roman(0) }.to raise_error(ArgumentError)
23
+ expect { Romanizer.to_roman(4000) }.to raise_error(ArgumentError)
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "romanizer"
4
+
5
+ RSpec.configure do |config|
6
+ # Enable flags like --only-failures and --next-failure
7
+ config.example_status_persistence_file_path = ".rspec_status"
8
+
9
+ # Disable RSpec exposing methods globally on `Module` and `main`
10
+ config.disable_monkey_patching!
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/romanizer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tecla21-romanizer"
7
+ spec.version = Romanizer::VERSION
8
+ spec.authors = ["tecla21"]
9
+ spec.email = ["geral@tecla21.ao"]
10
+
11
+ spec.summary = "Romanizer - Convert Integers to Roman Numerals and Vice-Versa."
12
+ spec.description = "Romanizer is a lightweight and efficient Ruby gem that provides seamless conversion between integers and Roman numerals. Whether you need to convert numbers to their Roman representations or decode Roman numerals back into integers, Romanizer makes it simple and reliable."
13
+ spec.homepage = "https://tecla21.ao"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/Tecla21/romanizer.git"
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ # gemspec = File.basename(__FILE__)
26
+ spec.files = Dir["**/*"]
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tecla21-romanizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tecla21
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Romanizer is a lightweight and efficient Ruby gem that provides seamless
14
+ conversion between integers and Roman numerals. Whether you need to convert numbers
15
+ to their Roman representations or decode Roman numerals back into integers, Romanizer
16
+ makes it simple and reliable.
17
+ email:
18
+ - geral@tecla21.ao
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - LICENSE
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - lib/romanizer.rb
33
+ - lib/romanizer/version.rb
34
+ - sig/romanizer.rbs
35
+ - spec/romanizer_spec.rb
36
+ - spec/spec_helper.rb
37
+ - tecla21-romanizer.gemspec
38
+ homepage: https://tecla21.ao
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://tecla21.ao
43
+ source_code_uri: https://github.com/Tecla21/romanizer.git
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.0.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.4.10
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Romanizer - Convert Integers to Roman Numerals and Vice-Versa.
63
+ test_files: []