roman-numerals 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.0"
12
+ end
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rspec (2.5.0)
12
+ rspec-core (~> 2.5.0)
13
+ rspec-expectations (~> 2.5.0)
14
+ rspec-mocks (~> 2.5.0)
15
+ rspec-core (2.5.1)
16
+ rspec-expectations (2.5.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.0.0)
25
+ jeweler (~> 1.6.0)
26
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Andrew Vos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = roman-numerals
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to roman-numerals
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Andrew Vos. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "roman-numerals"
18
+ gem.homepage = "http://github.com/AndrewVos/roman-numerals"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Roman numeral converter}
21
+ gem.description = %Q{Roman numeral converter}
22
+ gem.email = "andrew.vos@gmail.com"
23
+ gem.authors = ["Andrew Vos"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core/rake_task'
29
+ desc "Run specs"
30
+ RSpec::Core::RakeTask.new do |t|
31
+ t.rspec_opts = ['--colour']
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "roman-numerals #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,39 @@
1
+ class RomanNumerals
2
+ @base_digits = {
3
+ 1 => 'I',
4
+ 4 => 'IV',
5
+ 5 => 'V',
6
+ 9 => 'IX',
7
+ 10 => 'X',
8
+ 40 => 'XL',
9
+ 50 => 'L',
10
+ 90 => 'XC',
11
+ 100 => 'C',
12
+ 400 => 'CD',
13
+ 500 => 'D',
14
+ 900 => 'CM',
15
+ 1000 => 'M'
16
+ }
17
+
18
+ def self.to_roman(value)
19
+ result = ''
20
+ @base_digits.keys.reverse.each do |decimal|
21
+ while value >= decimal
22
+ value -= decimal
23
+ result += @base_digits[decimal]
24
+ end
25
+ end
26
+ result
27
+ end
28
+
29
+ def self.to_decimal(value)
30
+ result = 0
31
+ @base_digits.values.reverse.each do |roman|
32
+ while value.start_with? roman
33
+ value = value.slice(roman.length, value.length)
34
+ result += @base_digits.key roman
35
+ end
36
+ end
37
+ result
38
+ end
39
+ end
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{roman-numerals}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew Vos"]
12
+ s.date = %q{2011-05-02}
13
+ s.description = %q{Roman numeral converter}
14
+ s.email = %q{andrew.vos@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/roman-numerals.rb",
28
+ "roman-numerals.gemspec",
29
+ "spec/helper.rb",
30
+ "spec/roman-numerals_spec.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/AndrewVos/roman-numerals}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Roman numeral converter}
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<rspec>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
46
+ else
47
+ s.add_dependency(%q<rspec>, [">= 0"])
48
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rspec'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'roman-numerals'
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ describe RomanNumerals do
4
+ base_digits = {
5
+ 1 => 'I',
6
+ 4 => 'IV',
7
+ 5 => 'V',
8
+ 9 => 'IX',
9
+ 10 => 'X',
10
+ 40 => 'XL',
11
+ 50 => 'L',
12
+ 90 => 'XC',
13
+ 100 => 'C',
14
+ 400 => 'CD',
15
+ 500 => 'D',
16
+ 900 => 'CM',
17
+ 1000 => 'M'
18
+ }
19
+
20
+ describe ".to_roman" do
21
+ base_digits.each do |decimal, roman|
22
+ it "converts the decimal value #{decimal} to the roman value #{roman}" do
23
+ RomanNumerals.to_roman(decimal).should == roman
24
+ end
25
+ end
26
+ it "converts larger decimals" do
27
+ RomanNumerals.to_roman(23234).should == 'MMMMMMMMMMMMMMMMMMMMMMMCCXXXIV'
28
+ RomanNumerals.to_roman(42).should == 'XLII'
29
+ end
30
+ end
31
+ describe ".to_decimal" do
32
+ base_digits.each do |decimal, roman|
33
+ it "converts the roman value #{roman} to the decimal value #{decimal}" do
34
+ RomanNumerals.to_decimal(roman).should == decimal
35
+ end
36
+ end
37
+ it "converts larger roman numerals" do
38
+ RomanNumerals.to_decimal('MMMMMMMMMMMMMMMMMMMMMMMCCXXXIV').should == 23234
39
+ RomanNumerals.to_decimal('XLII').should == 42
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roman-numerals
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Andrew Vos
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-02 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 0
43
+ - 0
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 6
58
+ - 0
59
+ version: 1.6.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ description: Roman numeral converter
64
+ email: andrew.vos@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ files:
73
+ - .document
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ - Rakefile
79
+ - VERSION
80
+ - lib/roman-numerals.rb
81
+ - roman-numerals.gemspec
82
+ - spec/helper.rb
83
+ - spec/roman-numerals_spec.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/AndrewVos/roman-numerals
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: -4358736076031054528
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Roman numeral converter
117
+ test_files: []
118
+