roman_numericals 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: e4ec0184231a1496b9e99df099f728dd5e0c2919b4ee44dfa613dadd2a42c773
4
+ data.tar.gz: 045eefb6457c7497169923179ad6359e9549e76f40fdb4a94e4f6d23ad3cd9aa
5
+ SHA512:
6
+ metadata.gz: f73acf177480b992b0904aee2f6af27db6275e1b5ecae109fe1325ee715f58bd725b1bf455562868b8a6f2b94eae4e629989df49dc47ac72c39459b8b4591097
7
+ data.tar.gz: 4d196459e143c7ffe46cc3777dd514f5f2ede244ba5042c58b0e97df7056990858c58f678ea53893b24f9c1147aa0a767bdd77772bf38099477ad6dd751d5891
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in roman_numericals.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "test-unit", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ roman_numericals (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ power_assert (2.0.1)
10
+ rake (13.0.6)
11
+ test-unit (3.5.1)
12
+ power_assert
13
+
14
+ PLATFORMS
15
+ x86_64-darwin-19
16
+
17
+ DEPENDENCIES
18
+ rake (~> 13.0)
19
+ roman_numericals!
20
+ test-unit (~> 3.0)
21
+
22
+ BUNDLED WITH
23
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tomoya Bansho
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,60 @@
1
+ # RomanNumericals
2
+
3
+ *RomanNumericals* is a library to exchange arabic numbers to roman style.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'roman_numericals'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install roman_numericals
20
+
21
+ ## Usage
22
+ ### on code
23
+ Before usage, you should import this library code below:
24
+ ```ruby
25
+ require "roman_numericals"
26
+ ```
27
+
28
+ Also, you can exchange arabic number to roman style with codes below:
29
+ ```ruby
30
+ 9.to_roman # => IX
31
+ 100.ro_roman # => C
32
+ ```
33
+
34
+ If you will exchange not positive number under 3999, it will raise `InvalidNumberError`:
35
+ ```ruby
36
+ 0.to_roman # => InvalidNumberError
37
+ -1.to_roman # => InvalidNumberError
38
+ 4000.to_roman # => InvalidNumberError
39
+ ```
40
+
41
+ ### on CLI
42
+ You can on CLI.
43
+ ```bash
44
+ $ roman_numericals 9
45
+ IX
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomoya-kwansei/roman_numericals.
57
+
58
+ ## License
59
+
60
+ 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 "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "roman_numericals"
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
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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
+ #!/usr/bin/env ruby
2
+
3
+ require "roman_numericals"
4
+ ::RomanNumericals.main
5
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RomanNumericals
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "roman_numericals/version"
4
+
5
+ class InvalidNumberError < StandardError; end
6
+
7
+ class Integer
8
+ COUNT = 4
9
+ def to_roman
10
+ dict = [['I', 'V'], ['X', 'L'], ['C', 'D'], ['M', '']]
11
+ int = self
12
+ roman = ''
13
+ if self <= 0
14
+ raise InvalidNumberError.new("#{self} must be positive integer")
15
+ elsif self >= 4000
16
+ raise InvalidNumberError.new("#{self} must be under 4000")
17
+ end
18
+ COUNT.times do |i|
19
+ div, r = int.divmod(10)
20
+ a, b = dict[i]
21
+ c, d = dict[i + 1]
22
+ case
23
+ when r == 9 then
24
+ roman = "#{a}#{c}#{roman}"
25
+ when r == 4 then
26
+ roman = "#{a}#{b}#{roman}"
27
+ when r >= 5 then
28
+ roman = "#{b}#{a * (r - 5)}#{roman}"
29
+ when r < 4 then
30
+ roman = "#{a * r}#{roman}"
31
+ end
32
+ int = div
33
+ end
34
+ return roman
35
+ end
36
+ end
37
+
38
+ module RomanNumericals
39
+ class Error < StandardError; end
40
+
41
+ # Your code goes here...
42
+ module_function
43
+ def main
44
+ if ARGV.size > 0
45
+ puts ARGV[0].to_i.to_roman
46
+ else
47
+ puts "引数が1つ以上必要です"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/roman_numericals/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "roman_numericals"
7
+ spec.version = RomanNumericals::VERSION
8
+ spec.authors = ["Tomoya Bansho"]
9
+ spec.email = ["tomomail1997@gmail.com"]
10
+
11
+ spec.summary = "Transfer integer to roman style."
12
+ spec.description = "Transfer integer to roman style."
13
+ # spec.homepage = ""
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.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"] = "TODO: Put your gem's public repo URL here."
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
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roman_numericals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomoya Bansho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Transfer integer to roman style.
14
+ email:
15
+ - tomomail1997@gmail.com
16
+ executables:
17
+ - roman_numericals
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - exe/roman_numericals
29
+ - lib/roman_numericals.rb
30
+ - lib/roman_numericals/version.rb
31
+ - roman_numericals.gemspec
32
+ homepage:
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.2.32
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Transfer integer to roman style.
55
+ test_files: []