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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7194d45642dd9b89a1dc62a503f3706a2a42dee
4
- data.tar.gz: 166a2b66ce32ecbc84ca9e87f6fced62589f8e7c
3
+ metadata.gz: 89b363d82d917750d85be6555a64501035725677
4
+ data.tar.gz: 2896cc25697aaab5208dd64a65b5a10f4ab69d66
5
5
  SHA512:
6
- metadata.gz: 254ebfacd3d7a7ff8e9e9189864e9989c1e6b2f3540326ce0b56c5cee7b9c30ff6a613565fdd935b4d01ef1074814ece25a21643991685489d5b24816c30bc1c
7
- data.tar.gz: 7e36f7bba010e500a868e7a128af116940dabc2f1397c74c0792a4d27edf607e8ae93242979daf301aeae0309fca0ee591f288fa414e8040a0c3ac488027b59c
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
- TODO: Write usage instructions here
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
- <!-- ## Development
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
 
@@ -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 @currency == other.currency
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
  [
@@ -1,3 +1,3 @@
1
1
  module PuppyMoney
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-25 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler