arrabiata 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- ## Arabiata - dead simple conversion of roman <> arabian numerals
1
+ ## Arrabiata - dead simple conversion of roman letters <> arabic numerals
2
2
 
3
3
  ### Example
4
4
 
5
- >> Arabiata.to_arabian("MC")
5
+ >> Arrabiata.to_arabic("MC")
6
6
  => 1100
7
7
 
8
- >> Arabiata.to_roman(1100)
8
+ >> Arrabiata.to_roman(1100)
9
9
  => "MC"
data/Rakefile CHANGED
@@ -1,14 +1,16 @@
1
1
  require 'rake/testtask'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rake/gempackagetask'
4
+ require "yard"
5
+ require "yard/rake/yardoc_task"
4
6
 
5
7
  require 'jeweler'
6
8
  Jeweler::Tasks.new do |gem|
7
9
  gem.name = "arrabiata"
8
10
  gem.homepage = "http://github.com/invadersmustdie/arrabiata"
9
11
  gem.license = "MIT"
10
- gem.summary = %Q{dead simple conversion of roman <> arabian numerals}
11
- gem.description = %Q{dead simple conversion of roman <> arabian numerals}
12
+ gem.summary = %Q{dead simple conversion of roman <> arabic numerals}
13
+ gem.description = %Q{dead simple conversion of roman <> arabic numerals}
12
14
  gem.email = "rugek@dirtyhack.net"
13
15
  gem.authors = ["invadersmustdie"]
14
16
  end
@@ -19,4 +21,8 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
19
21
  spec.rspec_opts = ['--colour', '-f documentation', '--backtrace']
20
22
  end
21
23
 
24
+ YARD::Rake::YardocTask.new do |t|
25
+ t.files = FileList[ "lib/**/*.rb", "README.md"]
26
+ end
27
+
22
28
  task :default => [:spec]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.0
data/arrabiata.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{arrabiata}
8
- s.version = "0.1.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["invadersmustdie"]
12
- s.date = %q{2011-01-20}
13
- s.description = %q{dead simple conversion of roman <> arabian numerals}
12
+ s.date = %q{2011-12-26}
13
+ s.description = %q{dead simple conversion of roman <> arabic numerals}
14
14
  s.email = %q{rugek@dirtyhack.net}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  "VERSION",
24
24
  "arrabiata.gemspec",
25
25
  "lib/arrabiata.rb",
26
- "spec/arrabiata_to_arabian_spec.rb",
26
+ "spec/arrabiata_to_arabic_spec.rb",
27
27
  "spec/arrabiata_to_roman_spec.rb",
28
28
  "spec/spec_helper.rb"
29
29
  ]
@@ -31,9 +31,9 @@ Gem::Specification.new do |s|
31
31
  s.licenses = ["MIT"]
32
32
  s.require_paths = ["lib"]
33
33
  s.rubygems_version = %q{1.3.7}
34
- s.summary = %q{dead simple conversion of roman <> arabian numerals}
34
+ s.summary = %q{dead simple conversion of roman <> arabic numerals}
35
35
  s.test_files = [
36
- "spec/arrabiata_to_arabian_spec.rb",
36
+ "spec/arrabiata_to_arabic_spec.rb",
37
37
  "spec/arrabiata_to_roman_spec.rb",
38
38
  "spec/spec_helper.rb"
39
39
  ]
data/lib/arrabiata.rb CHANGED
@@ -4,34 +4,48 @@ class Arrabiata
4
4
  class UnknownRomanNumberError < ArrabiataError; end
5
5
 
6
6
  CONVERSION = {
7
- "M" => 1000,
8
- "D" => 500,
9
- "C" => 100,
10
- "L" => 50,
11
- "X" => 10,
12
- "V" => 5,
13
- "I" => 1
7
+ "M" => 1000,
8
+ "CM" => 900,
9
+ "D" => 500,
10
+ "CD" => 400,
11
+ "C" => 100,
12
+ "XC" => 90,
13
+ "L" => 50,
14
+ "XL" => 40,
15
+ "X" => 10,
16
+ "IX" => 9,
17
+ "V" => 5,
18
+ "IV" => 4,
19
+ "I" => 1
14
20
  }
15
21
 
22
+ # Converts arabic number to roman letters.
23
+ #
24
+ # @param [Fixnum] arabic number
25
+ # @return [String] roman letters
26
+ #
16
27
  def self.to_roman(n)
17
28
  raise ArgumentError, "first argument is not a Fixnum" if !n.is_a?(Fixnum)
18
29
  raise NoZeroInRomanNumbers, "roman numeral system doesn't include 0" if n == 0
19
30
 
20
31
  result = ""
21
32
 
22
- # NOTE: this version doesn't yet respects the subtractive principle
23
- CONVERSION.sort_by { |d| d.last }.reverse.each do |k|
24
- x = n / k.last
25
- if x != 0
26
- result << k.first * x
27
- n = n - x * k.last
33
+ CONVERSION.sort_by { |d| d.last }.reverse.each do |roman, arabic|
34
+ while(n >= arabic) do
35
+ result << roman
36
+ n -= arabic
28
37
  end
29
38
  end
30
39
 
31
40
  result
32
41
  end
33
42
 
34
- def self.to_arabian(str)
43
+ # Converts roman letters to arabic number.
44
+ #
45
+ # @param [String] roman letters
46
+ # @return [Fixnum] arabic number
47
+ #
48
+ def self.to_arabic(str)
35
49
  raise ArgumentError, "first argument is not a String" if !str.is_a?(String)
36
50
 
37
51
  result = 0
@@ -43,4 +57,10 @@ class Arrabiata
43
57
 
44
58
  result
45
59
  end
60
+
61
+ # @deprecated
62
+ # Use .to_arabic instead.
63
+ def self.to_arabian(str)
64
+ to_arabic(str)
65
+ end
46
66
  end
@@ -1,35 +1,35 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "Arrabiata -> to_arabian" do
3
+ describe "Arrabiata -> to_arabic" do
4
4
  it "should fail on characters not defined in roman numerals" do
5
5
  lambda {
6
- Arrabiata.to_arabian("MVVa")
6
+ Arrabiata.to_arabic("MVVa")
7
7
  }.should raise_error(Arrabiata::UnknownRomanNumberError, "'a' is not defined in roman numbers")
8
8
  end
9
9
 
10
10
  it "should fail on invalid argument passed" do
11
11
  lambda {
12
- Arrabiata.to_arabian(4.2)
12
+ Arrabiata.to_arabic(4.2)
13
13
  }.should raise_error(ArgumentError, "first argument is not a String")
14
14
  end
15
15
 
16
16
  it "should convert III to 3" do
17
- Arrabiata.to_arabian("III").should == 3
17
+ Arrabiata.to_arabic("III").should == 3
18
18
  end
19
19
 
20
20
  it "should convert VIII to 8" do
21
- Arrabiata.to_arabian("VIII").should == 8
21
+ Arrabiata.to_arabic("VIII").should == 8
22
22
  end
23
23
 
24
24
  it "should convert M to 1000" do
25
- Arrabiata.to_arabian("M").should == 1000
25
+ Arrabiata.to_arabic("M").should == 1000
26
26
  end
27
27
 
28
28
  it "should convert MIII to 1003" do
29
- Arrabiata.to_arabian("MIII").should == 1003
29
+ Arrabiata.to_arabic("MIII").should == 1003
30
30
  end
31
31
 
32
32
  it "should convert MMDCCCLV to 2855 " do
33
- Arrabiata.to_arabian("MMDCCCLV").should == 2855
33
+ Arrabiata.to_arabic("MMDCCCLV").should == 2855
34
34
  end
35
35
  end
@@ -32,4 +32,20 @@ describe "Arrabiata -> to_roman" do
32
32
  it "should convert 2855 to MMDCCCLV" do
33
33
  Arrabiata.to_roman(2855).should == "MMDCCCLV"
34
34
  end
35
+
36
+ it "should convert 79 to LXXIX" do
37
+ Arrabiata.to_roman(79).should == "LXXIX"
38
+ end
39
+
40
+ it "should convert 4 to IV" do
41
+ Arrabiata.to_roman(4).should == "IV"
42
+ end
43
+
44
+ it "should convert 19 to XIX" do
45
+ Arrabiata.to_roman(19).should == "XIX"
46
+ end
47
+
48
+ it "should convert 8759 to MMMMMMMMDCCLIX" do
49
+ Arrabiata.to_roman(8759).should == "MMMMMMMMDCCLIX"
50
+ end
35
51
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arrabiata
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 3
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - invadersmustdie
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-20 00:00:00 +01:00
18
+ date: 2011-12-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: dead simple conversion of roman <> arabian numerals
22
+ description: dead simple conversion of roman <> arabic numerals
23
23
  email: rugek@dirtyhack.net
24
24
  executables: []
25
25
 
@@ -35,7 +35,7 @@ files:
35
35
  - VERSION
36
36
  - arrabiata.gemspec
37
37
  - lib/arrabiata.rb
38
- - spec/arrabiata_to_arabian_spec.rb
38
+ - spec/arrabiata_to_arabic_spec.rb
39
39
  - spec/arrabiata_to_roman_spec.rb
40
40
  - spec/spec_helper.rb
41
41
  has_rdoc: true
@@ -71,8 +71,8 @@ rubyforge_project:
71
71
  rubygems_version: 1.3.7
72
72
  signing_key:
73
73
  specification_version: 3
74
- summary: dead simple conversion of roman <> arabian numerals
74
+ summary: dead simple conversion of roman <> arabic numerals
75
75
  test_files:
76
- - spec/arrabiata_to_arabian_spec.rb
76
+ - spec/arrabiata_to_arabic_spec.rb
77
77
  - spec/arrabiata_to_roman_spec.rb
78
78
  - spec/spec_helper.rb