cashrb 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +78 -75
- data/cashrb.gemspec +2 -2
- metadata +6 -6
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,78 +10,81 @@ providing what you need to get your job done.
|
|
10
10
|
Usage
|
11
11
|
-----
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
13
|
+
```ruby
|
14
|
+
require 'cashrb'
|
15
|
+
|
16
|
+
# Works with cents to avoid Floating point errors
|
17
|
+
n = Cash.new(100)
|
18
|
+
n.cents #=> 100
|
19
|
+
n.to_s #=> "1.00"
|
20
|
+
n.to_f #=> 1.0
|
21
|
+
|
22
|
+
# Don't like passing cents, set :from => :decimal and use a decimal value
|
23
|
+
n = Cash.new(1.11, from: :decimal)
|
24
|
+
n.cents #=> 111
|
25
|
+
n.to_s #=> "1.11"
|
26
|
+
n.to_f #=> 1.11
|
27
|
+
|
28
|
+
# Hate cents and always want to pass a decimal, just set the default
|
29
|
+
Cash.default_from = :decimal
|
30
|
+
n = Cash.new(1.11)
|
31
|
+
n.cents #=> 111
|
32
|
+
|
33
|
+
# Define currency as you see fit.
|
34
|
+
a = Cash.new(100, currency: :usd)
|
35
|
+
b = Cash.new(100, currency: :eur)
|
36
|
+
a + b #=> Error! Cash::IncompatibleCurrency
|
37
|
+
|
38
|
+
# Default is 100 cents in a dollar. Is your currency different, then just
|
39
|
+
# tell it.
|
40
|
+
n = Cash.new(100, cents_in_dollar: 5)
|
41
|
+
n.cents #=> 100
|
42
|
+
n.to_s #=> "20.0"
|
43
|
+
n.to_f #=> 20.0
|
44
|
+
|
45
|
+
n = Cash.new(100, cents_in_dollar: 10)
|
46
|
+
n.cents #=> 100
|
47
|
+
n.to_s #=> "10.0"
|
48
|
+
n.to_f #=> 10.0
|
49
|
+
|
50
|
+
n = Cash.new(100, cents_in_dollar: 1)
|
51
|
+
n.cents #=> 100
|
52
|
+
n.to_s #=> "100"
|
53
|
+
n.to_f #=> 100.0
|
54
|
+
|
55
|
+
# The default rounding method when dealing with fractional cents is
|
56
|
+
# BigDecimal::ROUND_HALF_UP. Would you rather use bankers rounding; just
|
57
|
+
# pass it as an argument.
|
58
|
+
n = Cash.new(2.5)
|
59
|
+
n.cents #=> 3
|
60
|
+
|
61
|
+
n = Cash.new(2.5, rounding_method: BigDecimal::ROUND_HALF_EVEN)
|
62
|
+
n.cents #=> 2
|
63
|
+
|
64
|
+
# Sick of specifying :cents_in_whole, :rounding_method and :currency; just
|
65
|
+
# set their defaults.
|
66
|
+
Cash.default_cents_in_whole = 10
|
67
|
+
Cash.default_rounding_method = BigDecimal::ROUND_DOWN
|
68
|
+
Cash.default_currency = :EUR
|
69
|
+
|
70
|
+
n = Cash.new(100)
|
71
|
+
n.to_s #=> "10.0"
|
72
|
+
n.to_f #=> 10.0
|
73
|
+
n.currency #=> :EUR
|
74
|
+
|
75
|
+
n = Cash.new(1.9)
|
76
|
+
n.cents #=> 1
|
77
|
+
|
78
|
+
# If your currency object implements :cents_in_whole, we'll go ahead and
|
79
|
+
# use that.
|
80
|
+
|
81
|
+
module MyCurrency
|
82
|
+
def self.cents_in_whole
|
83
|
+
10
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
n = Cash.new(9, :currency => MyCurrency)
|
88
|
+
n.to_f #=> 0.9
|
89
|
+
|
90
|
+
```
|
data/cashrb.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cashrb"
|
3
|
-
s.version = "1.3.
|
3
|
+
s.version = "1.3.1"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Shane Emmons"]
|
6
6
|
s.email = ["semmons99@gmail.com"]
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.required_ruby_version = ">= 1.8.7"
|
12
12
|
s.required_rubygems_version = ">= 1.3.6"
|
13
13
|
|
14
|
-
s.
|
14
|
+
s.add_development_dependency "minitest", "~> 2.2.0"
|
15
15
|
|
16
16
|
s.files = Dir.glob("{lib,test}/**/*")
|
17
17
|
s.files += %w(CHANGELOG.md LICENSE README.md)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cashrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &14789112 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.2.0
|
22
|
-
type: :
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14789112
|
25
25
|
description: Lightweight money and currency handler for working with financial calculations.
|
26
26
|
email:
|
27
27
|
- semmons99@gmail.com
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: 1.3.6
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.11
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: Lightweight money and currency handler for working with financial calculations.
|