rext 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ 0.6.2 / 2009-11-30
3
+ ==================
4
+
5
+ * Added Numeric#format_currency
6
+ * Refactored Numeric#format_currency 10.9999 now outputs 10.99
7
+
2
8
  0.6.1 / 2009-11-25
3
9
  ==================
4
10
 
data/Manifest CHANGED
@@ -20,6 +20,7 @@ lib/rext/module.rb
20
20
  lib/rext/module/helpers.rb
21
21
  lib/rext/numeric.rb
22
22
  lib/rext/numeric/bytes.rb
23
+ lib/rext/numeric/helpers.rb
23
24
  lib/rext/numeric/time.rb
24
25
  lib/rext/object.rb
25
26
  lib/rext/object/helpers.rb
data/README.rdoc CHANGED
@@ -74,6 +74,7 @@ Below are the methods currently provided by Rext.
74
74
  - to_seconds, to_minutes, to_hours, ...
75
75
  - ago / before
76
76
  - since / from_now
77
+ - format_currency
77
78
 
78
79
  * Hash
79
80
  - delete_at / extract!
data/lib/rext/numeric.rb CHANGED
@@ -4,4 +4,5 @@
4
4
  #++
5
5
 
6
6
  require 'rext/numeric/time'
7
- require 'rext/numeric/bytes'
7
+ require 'rext/numeric/bytes'
8
+ require 'rext/numeric/helpers'
@@ -0,0 +1,23 @@
1
+
2
+ class Numeric
3
+
4
+ ##
5
+ # Format a number as human readable currency.
6
+ #
7
+ # === Examples
8
+ #
9
+ # 10.format_currency => '10'
10
+ # 10.99.format_currency => '10.99'
11
+ # 10.9999.format_currency => '10.99'
12
+ # 1000.99.format_currency => '1,000.99'
13
+ # 1000000.99.format_currency => '1,000,000.99'
14
+ #
15
+
16
+ def format_currency
17
+ parts = self.to_s.split '.'
18
+ parts[0].gsub! /(\d)(?=(\d\d\d)+(?!\d))/, '\1,'
19
+ parts.join('.').gsub /(\.\d{2})(\d+)/, '\1'
20
+ rescue
21
+ self.to_s
22
+ end
23
+ end
data/lib/rext/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rext
3
- VERSION = '0.6.1'
3
+ VERSION = '0.6.2'
4
4
  end
data/rext.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rext}
5
- s.version = "0.6.1"
5
+ s.version = "0.6.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-11-25}
9
+ s.date = %q{2009-11-30}
10
10
  s.description = %q{Ruby extensions}
11
11
  s.email = %q{tj@vision-media.ca}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
13
- s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "benchmarks/enumerable.rb", "benchmarks/proc.rb", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "rext.gemspec", "spec/array_spec.rb", "spec/date_spec.rb", "spec/enumerable_spec.rb", "spec/hash_spec.rb", "spec/integer_spec.rb", "spec/module_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/symbol_spec.rb", "spec/time_spec.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/helpers.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
13
+ s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "benchmarks/enumerable.rb", "benchmarks/proc.rb", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/helpers.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "rext.gemspec", "spec/array_spec.rb", "spec/date_spec.rb", "spec/enumerable_spec.rb", "spec/hash_spec.rb", "spec/integer_spec.rb", "spec/module_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/symbol_spec.rb", "spec/time_spec.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
14
14
  s.homepage = %q{http://github.com/visionmedia/rext}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rext", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
data/spec/numeric_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe Numeric do
19
19
  end
20
20
  end
21
21
 
22
- describe "bytes" do
22
+ describe "#bytes" do
23
23
  it "should return bytes, kilobytes, megabytes, gigabytes, and terabytes" do
24
24
  5.bytes.should == 5
25
25
  5.kilobytes.should == 5120
@@ -28,4 +28,15 @@ describe Numeric do
28
28
  5.terabytes.should == 5497558138880
29
29
  end
30
30
  end
31
+
32
+ describe "#format_currency" do
33
+ it "should convert a number to a human readable delimited number" do
34
+ 10.format_currency.should == '10'
35
+ 10.9999.format_currency.should == '10.99'
36
+ 10.99.format_currency.should == '10.99'
37
+ 1_000.99.format_currency.should == '1,000.99'
38
+ 100_000.99.format_currency.should == '100,000.99'
39
+ 1_000_000.99.format_currency.should == '1,000,000.99'
40
+ end
41
+ end
31
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-25 00:00:00 -08:00
12
+ date: 2009-11-30 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,6 +37,7 @@ extra_rdoc_files:
37
37
  - lib/rext/module/helpers.rb
38
38
  - lib/rext/numeric.rb
39
39
  - lib/rext/numeric/bytes.rb
40
+ - lib/rext/numeric/helpers.rb
40
41
  - lib/rext/numeric/time.rb
41
42
  - lib/rext/object.rb
42
43
  - lib/rext/object/helpers.rb
@@ -80,6 +81,7 @@ files:
80
81
  - lib/rext/module/helpers.rb
81
82
  - lib/rext/numeric.rb
82
83
  - lib/rext/numeric/bytes.rb
84
+ - lib/rext/numeric/helpers.rb
83
85
  - lib/rext/numeric/time.rb
84
86
  - lib/rext/object.rb
85
87
  - lib/rext/object/helpers.rb