big_money 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  # vim: syntax=ruby
2
- bundle_path 'gems'
3
- disable_rubygems
4
- disable_system_gems
2
+ source 'https://rubygems.org'
5
3
 
6
- only :development do
4
+ group :development do
7
5
  gem 'jeweler'
8
6
  gem 'shoulda'
9
7
  gem 'hpricot'
10
8
  gem 'erubis'
9
+ gem 'rdoc'
11
10
  end
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.9)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ bourne (1.1.2)
8
+ mocha (= 0.10.5)
9
+ erubis (2.7.0)
10
+ git (1.2.5)
11
+ hpricot (0.8.6)
12
+ i18n (0.6.1)
13
+ jeweler (1.8.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ rdoc
18
+ json (1.7.5)
19
+ metaclass (0.0.1)
20
+ mocha (0.10.5)
21
+ metaclass (~> 0.0.1)
22
+ multi_json (1.5.0)
23
+ rake (10.0.3)
24
+ rdoc (3.12)
25
+ json (~> 1.4)
26
+ shoulda (3.3.2)
27
+ shoulda-context (~> 1.0.1)
28
+ shoulda-matchers (~> 1.4.1)
29
+ shoulda-context (1.0.2)
30
+ shoulda-matchers (1.4.2)
31
+ activesupport (>= 3.0.0)
32
+ bourne (~> 1.1.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ erubis
39
+ hpricot
40
+ jeweler
41
+ rdoc
42
+ shoulda
@@ -52,6 +52,11 @@ Represents an amount of money in a particular currency. Backed by BigDecimal, so
52
52
  require 'big_money'
53
53
  require 'big_money/exchange/yahoo' # Use yahoo finance exchange service.
54
54
 
55
+ # Cache it with memcache.
56
+ require 'moneta'
57
+ require 'moneta/memcache'
58
+ BigMoney::Exchange.cache = Moneta::Memcache.new(server: 'localhost', default_ttl: 3_600)
59
+
55
60
  bm = BigMoney.new('3.99', :usd)
56
61
  bm.amount #=> BigDecimal.new('3.99')
57
62
  bm.currency #=> BigMoney::Currency::USD
data/Rakefile CHANGED
@@ -1,20 +1,19 @@
1
1
  # encoding: utf-8
2
- require 'rubygems'
3
2
  require 'rake'
4
3
  require 'rake/testtask'
5
- require 'rake/rdoctask'
4
+ require 'rdoc/task'
6
5
 
7
6
  begin
8
7
  require 'jeweler'
9
8
  Jeweler::Tasks.new do |gem|
10
9
  gem.name = 'big_money'
11
- gem.summary = %q{BigDecimal backed amount of money in a particular currency.}
10
+ gem.description = %q{BigDecimal backed amount of money in a particular currency.}
12
11
  gem.email = ['shane.hanna@gmail.com', 'mroch@cmu.edu']
13
12
  gem.homepage = 'http://github.com/shanna/big_money'
14
13
  gem.authors = ['Shane Hanna', 'Marshall Roch']
15
14
  gem.executables = [] # Only ever bundled development executables in bin/*
16
15
  end
17
- Jeweler::GemcutterTasks.new
16
+ Jeweler::RubygemsDotOrgTasks.new
18
17
  rescue LoadError
19
18
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
19
  end
@@ -25,7 +24,7 @@ Rake::TestTask.new(:test) do |test|
25
24
  test.verbose = true
26
25
  end
27
26
 
28
- Rake::RDocTask.new do |rdoc|
27
+ RDoc::Task.new do |rdoc|
29
28
  if File.exist?('VERSION.yml')
30
29
  config = YAML.load(File.read('VERSION.yml'))
31
30
  version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 1
3
3
  :minor: 2
4
- :patch: 0
4
+ :patch: 1
5
5
  :build:
@@ -1,65 +1,72 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{big_money}
8
- s.version = "1.2.0"
7
+ s.name = "big_money"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shane Hanna", "Marshall Roch"]
12
- s.date = %q{2010-05-27}
12
+ s.date = "2012-12-20"
13
+ s.description = "BigDecimal backed amount of money in a particular currency."
13
14
  s.email = ["shane.hanna@gmail.com", "mroch@cmu.edu"]
14
15
  s.extra_rdoc_files = [
15
16
  "LICENSE",
16
- "README.rdoc"
17
+ "README.rdoc"
17
18
  ]
18
19
  s.files = [
19
20
  ".document",
20
- ".gitignore",
21
- "Gemfile",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION.yml",
26
- "big_money.gemspec",
27
- "lib/big_money.rb",
28
- "lib/big_money/currency.rb",
29
- "lib/big_money/currency/iso4217.rb",
30
- "lib/big_money/exchange.rb",
31
- "lib/big_money/exchange/yahoo.rb",
32
- "lib/big_money/parser.rb",
33
- "lib/big_money/types.rb",
34
- "rakelib/iso4217.rb",
35
- "rakelib/iso4217.rb.erb",
36
- "test/helper.rb",
37
- "test/test_big_money.rb",
38
- "test/test_currency.rb",
39
- "test/test_exchange.rb",
40
- "test/test_parser.rb"
41
- ]
42
- s.homepage = %q{http://github.com/shanna/big_money}
43
- s.rdoc_options = ["--charset=UTF-8"]
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.6}
46
- s.summary = %q{BigDecimal backed amount of money in a particular currency.}
47
- s.test_files = [
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION.yml",
27
+ "big_money.gemspec",
28
+ "lib/big_money.rb",
29
+ "lib/big_money/currency.rb",
30
+ "lib/big_money/currency/iso4217.rb",
31
+ "lib/big_money/exchange.rb",
32
+ "lib/big_money/exchange/yahoo.rb",
33
+ "lib/big_money/parser.rb",
34
+ "lib/big_money/types.rb",
35
+ "rakelib/iso4217.rb",
36
+ "rakelib/iso4217.rb.erb",
37
+ "test/helper.rb",
38
+ "test/test_big_money.rb",
39
+ "test/test_currency.rb",
48
40
  "test/test_exchange.rb",
49
- "test/test_currency.rb",
50
- "test/test_big_money.rb",
51
- "test/test_parser.rb",
52
- "test/helper.rb"
41
+ "test/test_parser.rb"
53
42
  ]
43
+ s.homepage = "http://github.com/shanna/big_money"
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = "1.8.23"
46
+ s.summary = nil
54
47
 
55
48
  if s.respond_to? :specification_version then
56
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
57
49
  s.specification_version = 3
58
50
 
59
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<hpricot>, [">= 0"])
55
+ s.add_development_dependency(%q<erubis>, [">= 0"])
56
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
60
57
  else
58
+ s.add_dependency(%q<jeweler>, [">= 0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<hpricot>, [">= 0"])
61
+ s.add_dependency(%q<erubis>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, [">= 0"])
61
63
  end
62
64
  else
65
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_dependency(%q<hpricot>, [">= 0"])
68
+ s.add_dependency(%q<erubis>, [">= 0"])
69
+ s.add_dependency(%q<rdoc>, [">= 0"])
63
70
  end
64
71
  end
65
72
 
@@ -78,6 +78,14 @@ class BigMoney
78
78
  end
79
79
  end
80
80
 
81
+ def zero?
82
+ amount.zero?
83
+ end
84
+
85
+ def nonzero?
86
+ amount.nonzero? && self
87
+ end
88
+
81
89
  def <=>(money)
82
90
  money.kind_of?(self.class) ? (currency <=> money.currency).nonzero? || (amount <=> money.amount).nonzero? || 0 : nil
83
91
  end
@@ -41,12 +41,13 @@ class BigMoney
41
41
  # No caching is done by default. You can set one though using anything that behaves like a Hash for example the
42
42
  # moneta library.
43
43
  #
44
- # ==== Example
44
+ # ==== Cache
45
45
  #
46
46
  # require 'bigmoney/exchanage'
47
+ # require 'moneta'
47
48
  # require 'moneta/memcache'
48
49
  #
49
- # BigMoney::Exchange.cache = Moneta::Memcache.new('localhost', default_ttl: 3_600)
50
+ # BigMoney::Exchange.cache = Moneta::Memcache.new(server: 'localhost', default_ttl: 3_600)
50
51
  class Exchange
51
52
  class ConversionError < StandardError; end
52
53
 
@@ -1,7 +1,5 @@
1
- root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
2
-
3
- require File.join(root, 'gems', 'environment')
4
- Bundler.require_env(:development)
1
+ require 'bundler'
2
+ Bundler.setup(:development)
5
3
  require 'test/unit'
6
4
 
7
5
  begin
@@ -11,6 +9,7 @@ rescue LoadError
11
9
  exit 1
12
10
  end
13
11
 
12
+ root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
14
13
  $:.unshift File.join(root, 'lib'), File.dirname(__FILE__)
15
14
  require 'big_money'
16
15
 
@@ -97,6 +97,22 @@ class TestBigMoney < Test::Unit::TestCase
97
97
  assert_equal BigMoney.new(1), -BigMoney.new(-1)
98
98
  assert_equal BigMoney.new(1), -BigMoney.new(-1)
99
99
  end
100
+
101
+ should 'zero?' do
102
+ assert_equal BigMoney.new(-1.05).zero?, false
103
+ assert_equal BigMoney.new(0).zero?, true
104
+ assert_equal BigMoney.new(0.0).zero?, true
105
+ assert_equal BigMoney.new(1).zero?, false
106
+ assert_equal BigMoney.new(1.05).zero?, false
107
+ end
108
+
109
+ should 'nonzero?' do
110
+ assert_equal BigMoney.new(-1.05).nonzero?, BigMoney.new(-1.05)
111
+ assert_equal BigMoney.new(0).nonzero?, nil
112
+ assert_equal BigMoney.new(0.0).nonzero?, nil
113
+ assert_equal BigMoney.new(1).nonzero?, BigMoney.new(1)
114
+ assert_equal BigMoney.new(1.05).nonzero?, BigMoney.new(1.05)
115
+ end
100
116
  end
101
117
 
102
118
  context 'serialization' do
metadata CHANGED
@@ -1,39 +1,110 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: big_money
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 0
9
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shane Hanna
13
9
  - Marshall Roch
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2010-05-27 00:00:00 +10:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description:
23
- email:
13
+ date: 2012-12-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jeweler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: shoulda
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: hpricot
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: erubis
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rdoc
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: BigDecimal backed amount of money in a particular currency.
96
+ email:
24
97
  - shane.hanna@gmail.com
25
98
  - mroch@cmu.edu
26
99
  executables: []
27
-
28
100
  extensions: []
29
-
30
- extra_rdoc_files:
101
+ extra_rdoc_files:
31
102
  - LICENSE
32
103
  - README.rdoc
33
- files:
104
+ files:
34
105
  - .document
35
- - .gitignore
36
106
  - Gemfile
107
+ - Gemfile.lock
37
108
  - LICENSE
38
109
  - README.rdoc
39
110
  - Rakefile
@@ -53,39 +124,31 @@ files:
53
124
  - test/test_currency.rb
54
125
  - test/test_exchange.rb
55
126
  - test/test_parser.rb
56
- has_rdoc: true
57
127
  homepage: http://github.com/shanna/big_money
58
128
  licenses: []
59
-
60
129
  post_install_message:
61
- rdoc_options:
62
- - --charset=UTF-8
63
- require_paths:
130
+ rdoc_options: []
131
+ require_paths:
64
132
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- segments:
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ segments:
70
140
  - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
- version: "0"
141
+ hash: -1594666296486135105
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
79
148
  requirements: []
80
-
81
149
  rubyforge_project:
82
- rubygems_version: 1.3.6
150
+ rubygems_version: 1.8.23
83
151
  signing_key:
84
152
  specification_version: 3
85
- summary: BigDecimal backed amount of money in a particular currency.
86
- test_files:
87
- - test/test_exchange.rb
88
- - test/test_currency.rb
89
- - test/test_big_money.rb
90
- - test/test_parser.rb
91
- - test/helper.rb
153
+ summary: ''
154
+ test_files: []
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
6
- gems/*
7
- bin/*