Skip to content

Instantly share code, notes, and snippets.

@bash0C7
Created June 2, 2012 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bash0C7/2856738 to your computer and use it in GitHub Desktop.
Save bash0C7/2856738 to your computer and use it in GitHub Desktop.
#minatork01 pink-one(sakurai & koshiba)
# -*- coding: utf-8
require 'pry'
class Fixnum
def numerals
if self < 20
case self
when 0
'zero'
when 1
'one'
when 2
'two'
when 3
'three'
when 4
'four'
when 5
'five'
when 6
'six'
when 7
'seven'
when 8
'eight'
when 9
'nine'
when 10
'ten'
end
else
case
when self < 30
fuga('twenty', 20)
when self < 40
fuga('thirty', 30)
when self >= 100 && self < 1000
hyaku = (self / 100).to_i;
result = hyaku.numerals + '-hundred'
result += ' ' + (self - hyaku * 100).numerals unless self % 100 == 0
result
when self >= 1000
hyaku = (self / 1000).to_i;
result = hyaku.numerals + '-thousand'
result += ' ' + (self - hyaku * 1000).numerals unless self % 1000 == 0
result
end
end
end
def fuga(string, number)
result = ''
result += string
hoge = self - number
result += '-' + hoge.numerals unless hoge == 0
result
end
end
describe 'Numerals' do
before :all do
end
context '決め打ち' do
it '0' do
0.numerals.should == 'zero'
end
it '1' do
1.numerals.should == 'one'
end
it '2' do
2.numerals.should == 'two'
end
it '3' do
3.numerals.should == 'three'
end
it '4' do
4.numerals.should == 'four'
end
it '5' do
5.numerals.should == 'five'
end
it '6' do
6.numerals.should == 'six'
end
it '7' do
7.numerals.should == 'seven'
end
it '8' do
8.numerals.should == 'eight'
end
it '9' do
9.numerals.should == 'nine'
end
it '10' do
10.numerals.should == 'ten'
end
it '20' do
20.numerals.should == 'twenty'
end
end
context "ロジックで求める" do
it '21' do
21.numerals.should == 'twenty-one'
end
it '31' do
31.numerals.should == 'thirty-one'
end
it 100 do
100.numerals.should == 'one-hundred'
end
it 121 do
121.numerals.should == 'one-hundred twenty-one'
end
it 130 do
121.numerals.should == 'one-hundred twenty-one'
end
it 200 do
200.numerals.should == 'two-hundred'
end
it 1000 do
1000.numerals.should == 'one-thousand'
end
it 1231 do
1231.numerals.should == 'one-thousand two-hundred thirty-one'
end
it 2000 do
1000.numerals.should == 'one-thousand'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment