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