cashrb 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +78 -75
  3. data/cashrb.gemspec +2 -2
  4. metadata +6 -6
@@ -1,3 +1,7 @@
1
+ cashrb v1.3.1
2
+ =============
3
+ - update minitest to be a development dependency not a runtime dependency
4
+
1
5
  cashrb v1.3.0
2
6
  =============
3
7
  - add #abs
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
- require 'cashrb'
14
-
15
- # Works with cents to avoid Floating point errors
16
- n = Cash.new(100)
17
- n.cents #=> 100
18
- n.to_s #=> "1.00"
19
- n.to_f #=> 1.0
20
-
21
- # Don't like passing cents, set :from => :decimal and use a decimal value
22
- n = Cash.new(1.11, from: :decimal)
23
- n.cents #=> 111
24
- n.to_s #=> "1.11"
25
- n.to_f #=> 1.11
26
-
27
- # Hate cents and always want to pass a decimal, just set the default
28
- Cash.default_from = :decimal
29
- n = Cash.new(1.11)
30
- n.cents #=> 111
31
-
32
- # Define currency as you see fit.
33
- a = Cash.new(100, currency: :usd)
34
- b = Cash.new(100, currency: :eur)
35
- a + b #=> Error! Cash::IncompatibleCurrency
36
-
37
- # Default is 100 cents in a dollar. Is your currency different, then just
38
- # tell it.
39
- n = Cash.new(100, cents_in_dollar: 5)
40
- n.cents #=> 100
41
- n.to_s #=> "20.0"
42
- n.to_f #=> 20.0
43
-
44
- n = Cash.new(100, cents_in_dollar: 10)
45
- n.cents #=> 100
46
- n.to_s #=> "10.0"
47
- n.to_f #=> 10.0
48
-
49
- n = Cash.new(100, cents_in_dollar: 1)
50
- n.cents #=> 100
51
- n.to_s #=> "100"
52
- n.to_f #=> 100.0
53
-
54
- # The default rounding method when dealing with fractional cents is
55
- # BigDecimal::ROUND_HALF_UP. Would you rather use bankers rounding; just
56
- # pass it as an argument.
57
- n = Cash.new(2.5)
58
- n.cents #=> 3
59
-
60
- n = Cash.new(2.5, rounding_method: BigDecimal::ROUND_HALF_EVEN)
61
- n.cents #=> 2
62
-
63
- # Sick of specifying :cents_in_whole, :rounding_method and :currency; just
64
- # set their defaults.
65
- Cash.default_cents_in_whole = 10
66
- Cash.default_rounding_method = BigDecimal::ROUND_DOWN
67
- Cash.default_currency = :EUR
68
-
69
- n = Cash.new(100)
70
- n.to_s #=> "10.0"
71
- n.to_f #=> 10.0
72
- n.currency #=> :EUR
73
-
74
- n = Cash.new(1.9)
75
- n.cents #=> 1
76
-
77
- # If your currency object implements :cents_in_whole, we'll go ahead and
78
- # use that.
79
-
80
- module MyCurrency
81
- def self.cents_in_whole
82
- 10
83
- end
84
- end
85
-
86
- n = Cash.new(9, :currency => MyCurrency)
87
- n.to_f #=> 0.9
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
+ ```
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cashrb"
3
- s.version = "1.3.0"
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.add_dependency "minitest", "~> 2.2.0"
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.0
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: 2011-11-11 00:00:00.000000000Z
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: &16572528 !ruby/object:Gem::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: :runtime
22
+ type: :development
23
23
  prerelease: false
24
- version_requirements: *16572528
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.5
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.