puppy_money 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +43 -3
- data/lib/puppy_money/money.rb +3 -1
- data/lib/puppy_money/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89b363d82d917750d85be6555a64501035725677
|
4
|
+
data.tar.gz: 2896cc25697aaab5208dd64a65b5a10f4ab69d66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b583c2b1434c135f71481df27025732284afb9e08e612b26de187de0a8e5e9897afa1743ccb1e9bf9266ba2fa2851a9f860e59688d7a94a61b1416a57c236ab8
|
7
|
+
data.tar.gz: 7e7001334e69ac502dc4cc8b87186f9b7d3d963c47767e5bb112af9455f342c1493ab1138d450dd121bb91032c8ee456abbb89007a3f1167312b52752c8eeb00
|
data/README.md
CHANGED
@@ -19,14 +19,54 @@ Or install it yourself as:
|
|
19
19
|
$ gem install puppy_money
|
20
20
|
|
21
21
|
## Usage
|
22
|
+
Woof.
|
22
23
|
|
23
|
-
|
24
|
+
Conversion money using real-time rates
|
25
|
+
```ruby
|
26
|
+
# Instantiate money objects:
|
27
|
+
|
28
|
+
fifty_eur = Money.new(50, 'EUR')
|
29
|
+
|
30
|
+
# Get amount and currency:
|
31
|
+
|
32
|
+
fifty_eur.amount # => 50
|
33
|
+
fifty_eur.currency # => "EUR"
|
34
|
+
fifty_eur.inspect # => "50.00 EUR"
|
35
|
+
|
36
|
+
# Convert to a different currency with up to date exchange rates
|
37
|
+
|
38
|
+
# exchange rate April 26, 2017
|
39
|
+
fifty_eur.convert_to('USD') # => 54.46 USD
|
40
|
+
|
41
|
+
# Perform operations in different currencies:
|
42
|
+
|
43
|
+
## Arithmetic
|
44
|
+
|
45
|
+
fifty_eur + twenty_dollars # => 68.02 EUR
|
46
|
+
fifty_eur - twenty_dollars # => 31.98 EUR
|
47
|
+
fifty_eur / 2 # => 25 EUR
|
48
|
+
twenty_dollars * 3 # => 60 USD
|
49
|
+
|
50
|
+
## Comparisons (also in different currencies):
|
51
|
+
|
52
|
+
twenty_dollars == Money.new(20, 'USD') # => true
|
53
|
+
twenty_dollars == Money.new(30, 'USD') # => false
|
54
|
+
|
55
|
+
fifty_eur_in_usd = fifty_eur.convert_to('USD')
|
56
|
+
fifty_eur_in_usd == fifty_eur # => true
|
57
|
+
|
58
|
+
twenty_dollars > Money.new(5, 'USD') # => true
|
59
|
+
twenty_dollars < fifty_eur # => true
|
60
|
+
```
|
61
|
+
|
62
|
+
## TODO
|
63
|
+
Implement functionality for manually inputted currencies and non-standard currencies
|
24
64
|
|
25
|
-
|
65
|
+
## Development
|
26
66
|
|
27
67
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
68
|
|
29
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
70
|
|
31
71
|
## Contributing
|
32
72
|
|
data/lib/puppy_money/money.rb
CHANGED
@@ -42,7 +42,9 @@ class Money
|
|
42
42
|
[:+, :-, :*, :/, :==, :>, :>=, :<, :<=, :<=>].each do |operation|
|
43
43
|
define_method(operation) do |other|
|
44
44
|
if [:+, :-, :*, :/].include? operation
|
45
|
-
if
|
45
|
+
if other.is_a? Numeric
|
46
|
+
Money.new(@amount.public_send(operation, other), @currency)
|
47
|
+
elsif @currency == other.currency
|
46
48
|
Money.new(@amount.public_send(operation, other.amount), @currency)
|
47
49
|
else
|
48
50
|
[
|
data/lib/puppy_money/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppy_money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Kreiger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|