rupees 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Manifest +4 -0
  2. data/README.rdoc +18 -0
  3. data/Rakefile +14 -0
  4. data/lib/rupees.rb +51 -0
  5. data/rupees.gemspec +30 -0
  6. metadata +65 -0
@@ -0,0 +1,4 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/rupees.rb
4
+ Manifest
@@ -0,0 +1,18 @@
1
+ Rupees
2
+
3
+ Using Rupees you can write number to words (as Indian rupee).
4
+
5
+ This is easy and self explanatory.
6
+
7
+
8
+ How To Use:
9
+
10
+ Eg:
11
+ 2345.rupees
12
+
13
+ Output:
14
+ Two thousand, Three hundred, FourtyFive Rupees.
15
+
16
+
17
+ Thats it. :)
18
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rupees', '0.1.0') do |p|
6
+ p.description = "Convert number to Indian rupee(Rs)"
7
+ p.url = "http://github.com/railsfactory-shiv/rupees"
8
+ p.author = "Shiv Singh"
9
+ p.email = "shivsingh@railsfactory.org"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|ext| load ext}
@@ -0,0 +1,51 @@
1
+ module NumberToRupees
2
+ WORDS = {0=>"zero", 1=>"One", 2=>"Two", 3=>"Three", 4=>"Four", 5=>"Five", 6=>"six", 7=>"seven", 8=>"Eight", 9=>"Nine",10=>"Ten",11=>"Eleven",12=>"Twelve",13=>"Thirteen",14=>"Fourteen",15=>"Fifteen",16=>"Sixteen",17=>"Seventeen",18=>"Eighteen",19=>"Nineteen",20=>"Twenty",30=>"Thirty",40=>"Fourty",50=>"Fifty",60=>"Sixty",70=>"Seventy",80=>"Eighty",90=>"Ninty"}
3
+ SUFIXES = {0=>"hundred & ", 1=>" Crore, ", 2=>" Lakh, ", 3=>" Thousand, ", 4=>" Hundred, "} # 5=>''
4
+ module Fixnum
5
+ def self.included(recipient)
6
+ recipient.extend(ClassMethods)
7
+ recipient.class_eval do
8
+ include InstanceMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ end
14
+
15
+ module InstanceMethods
16
+ def rupees
17
+ result = self >= 0 ? "" : "(-) "
18
+ num = self.abs
19
+
20
+ # I would prefer One Rupee, insead of One Rupees
21
+ return "One Rupee." if num==1
22
+
23
+ if num > 99
24
+ num.to_s.rjust(11,'0').insert(-4,'0').scan(/../).each_with_index{|x,i| result += self.def_calc(x,i) }
25
+ else
26
+ result = spell_two_digits(num)
27
+ end
28
+ result.sub(/,\s$/,'')+ " Rupees."
29
+ end
30
+
31
+ protected
32
+ def def_calc(x,i)
33
+ str=self.proc_unit(x)
34
+ return '' if str.length==0
35
+ return "#{str}#{SUFIXES[i]}"
36
+ end
37
+
38
+ def proc_unit(x)
39
+ return "" unless x.to_i > 0
40
+ return spell_two_digits(x.to_i)
41
+ end
42
+
43
+ def spell_two_digits(x)
44
+ return WORDS[x] if WORDS[x]
45
+ r,f = x.divmod(10)
46
+ return "#{WORDS[r*10]}#{WORDS[f]}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ Fixnum.send :include, NumberToRupees::Fixnum
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rupees}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Shiv Singh"]
9
+ s.date = %q{2009-11-15}
10
+ s.description = %q{Convert number to Indian rupee in words}
11
+ s.email = %q{shivsingh@railsfactory.org}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/rupees.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/rupees.rb", "Manifest", "rupees.gemspec"]
14
+ s.homepage = %q{http://github.com/railsfactory-shiv/rupees}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rupees", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rupees}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Convert number to Indian rupee(Rs)}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rupees
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shiv Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-15 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Convert number to Indian rupee in words
17
+ email: shivsingh@railsfactory.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - lib/rupees.rb
25
+ files:
26
+ - README.rdoc
27
+ - Rakefile
28
+ - lib/rupees.rb
29
+ - Manifest
30
+ - rupees.gemspec
31
+ has_rdoc: true
32
+ homepage: http://github.com/railsfactory-shiv/rupees
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --line-numbers
38
+ - --inline-source
39
+ - --title
40
+ - Rupees
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.2"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: rupees
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Convert number to Indian rupee(Rs)
64
+ test_files: []
65
+