currency 0.1.0
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.
- data.tar.gz.sig +1 -0
- data/ChangeLog +5 -0
- data/README +33 -0
- data/Rakefile +349 -0
- data/Releases +6 -0
- data/TODO +0 -0
- data/examples/ex1.rb +13 -0
- data/examples/xe1.rb +19 -0
- data/lib/currency.rb +13 -0
- data/lib/currency/active_record.rb +70 -0
- data/lib/currency/core_extensions.rb +25 -0
- data/lib/currency/currency.rb +203 -0
- data/lib/currency/currency_exchange.rb +50 -0
- data/lib/currency/currency_exchange_test.rb +27 -0
- data/lib/currency/currency_exchange_xe.rb +140 -0
- data/lib/currency/currency_factory.rb +73 -0
- data/lib/currency/currency_version.rb +6 -0
- data/lib/currency/exception.rb +10 -0
- data/lib/currency/exchange_rate.rb +47 -0
- data/lib/currency/money.rb +190 -0
- data/lib/currency/money_helper.rb +12 -0
- data/scripts/gemdoc.rb +62 -0
- data/test/money_test.rb +166 -0
- data/test/test_base.rb +31 -0
- data/test/xe_test.rb +33 -0
- metadata +90 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
)͍�����[�����֕�p|z;���&����ЃV1tD����B��PF�b���&�该0w��%[P�����uy��G��M-���J��D���4`"곮��m{QM4O�Uv�D��]_
|
data/ChangeLog
ADDED
data/README
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= Currency
|
2
|
+
|
3
|
+
This is the rubyforge.com Currency package.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install currency
|
8
|
+
|
9
|
+
== For User Documentation, see
|
10
|
+
|
11
|
+
This package deals with currencies, conversions between currencies and monetary values in an object-oriented fashion.
|
12
|
+
|
13
|
+
== Home page
|
14
|
+
|
15
|
+
* {Currency Home}[http://currency.rubyforge.org]
|
16
|
+
|
17
|
+
== Additional directories
|
18
|
+
|
19
|
+
[./lib/...] the Currency library
|
20
|
+
[./test/...] unit and functional test
|
21
|
+
[./examples/...] example programs
|
22
|
+
|
23
|
+
== Credits
|
24
|
+
|
25
|
+
Currency was developed by:
|
26
|
+
|
27
|
+
* Kurt Stephens -- ruby-currency(at)umleta.com
|
28
|
+
|
29
|
+
== Contributors
|
30
|
+
|
31
|
+
Maybe you?
|
32
|
+
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,349 @@
|
|
1
|
+
# Rakefile for currency -*- ruby -*-
|
2
|
+
# Adapted from RubyGems/Rakefile
|
3
|
+
# upload_package NOT WORKING YET
|
4
|
+
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/packagetask'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
def announce(msg='')
|
13
|
+
STDERR.puts msg
|
14
|
+
end
|
15
|
+
|
16
|
+
PKG_Name = 'Currency'
|
17
|
+
PKG_NAME = PKG_Name.gsub(/[a-z][A-Z]/) {|x| "#{x[0,1]}_#{x[1,1]}"}.downcase
|
18
|
+
RUBY_FORGE_PROJECT = PKG_NAME
|
19
|
+
|
20
|
+
def package_version
|
21
|
+
'0.1.0'
|
22
|
+
end
|
23
|
+
|
24
|
+
if ENV['REL']
|
25
|
+
PKG_VERSION = ENV['REL']
|
26
|
+
CURRENT_VERSION = package_version
|
27
|
+
else
|
28
|
+
PKG_VERSION = package_version
|
29
|
+
CURRENT_VERSION = PKG_VERSION
|
30
|
+
end
|
31
|
+
|
32
|
+
CLEAN.include("COMMENTS")
|
33
|
+
CLOBBER.include(
|
34
|
+
"test/data",
|
35
|
+
"test/temp",
|
36
|
+
'scripts/*.hieraki',
|
37
|
+
'data__',
|
38
|
+
'html',
|
39
|
+
'pkgs/sources/sources*.gem',
|
40
|
+
'.config',
|
41
|
+
'**/debug.log',
|
42
|
+
'**/development.log',
|
43
|
+
'logs'
|
44
|
+
)
|
45
|
+
|
46
|
+
task :default => [:test]
|
47
|
+
|
48
|
+
Rake::TestTask.new(:test) do |t|
|
49
|
+
t.test_files = FileList['test/*test*.rb']
|
50
|
+
end
|
51
|
+
|
52
|
+
Rake::TestTask.new(:functional) do |t|
|
53
|
+
t.test_files = FileList['test/functional*.rb']
|
54
|
+
end
|
55
|
+
|
56
|
+
Rake::TestTask.new(:alltests) do |t|
|
57
|
+
t.test_files = FileList['test/{*test,functional}*.rb']
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Run the tests for a build"
|
61
|
+
task :build_tests do
|
62
|
+
html_dir = ENV['TESTRESULTS'] || 'html/tests'
|
63
|
+
ruby %{-Ilib scripts/buildtests.rb #{html_dir}}
|
64
|
+
open("#{html_dir}/summary.html") do |inf|
|
65
|
+
open("#{html_dir}/summary.new", "w") do |outf|
|
66
|
+
inf.each do |line|
|
67
|
+
if line =~ /td align/
|
68
|
+
line = " <td align=\"left\">#{Time.now}</td><td align=\"right\">"
|
69
|
+
end
|
70
|
+
outf.puts line
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
mv "#{html_dir}/summary.html", "#{html_dir}/summary.old"
|
75
|
+
mv "#{html_dir}/summary.new", "#{html_dir}/summary.html"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Shortcuts for test targets
|
79
|
+
task :tf => [:functional]
|
80
|
+
task :tu => [:test]
|
81
|
+
task :ta => [:alltests]
|
82
|
+
|
83
|
+
task :gemtest do
|
84
|
+
ruby %{-Ilib -rscripts/runtest -e 'run_tests("test/test_gempaths.rb", true)'}
|
85
|
+
end
|
86
|
+
|
87
|
+
# --------------------------------------------------------------------
|
88
|
+
# Creating a release
|
89
|
+
|
90
|
+
desc "Make a new release"
|
91
|
+
task :release => [
|
92
|
+
:prerelease,
|
93
|
+
:clobber,
|
94
|
+
:alltests,
|
95
|
+
:update_version,
|
96
|
+
:package,
|
97
|
+
:tag] do
|
98
|
+
|
99
|
+
announce
|
100
|
+
announce "**************************************************************"
|
101
|
+
announce "* Release #{PKG_VERSION} Complete."
|
102
|
+
announce "* Packages ready to upload."
|
103
|
+
announce "**************************************************************"
|
104
|
+
announce
|
105
|
+
end
|
106
|
+
|
107
|
+
# Validate that everything is ready to go for a release.
|
108
|
+
task :prerelease do
|
109
|
+
announce
|
110
|
+
announce "**************************************************************"
|
111
|
+
announce "* Making #{PKG_Name} Release #{PKG_VERSION}"
|
112
|
+
announce "* (current version #{CURRENT_VERSION})"
|
113
|
+
announce "**************************************************************"
|
114
|
+
announce
|
115
|
+
|
116
|
+
# Is a release number supplied?
|
117
|
+
unless ENV['REL']
|
118
|
+
fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Is the release different than the current release.
|
122
|
+
# (or is REUSE set?)
|
123
|
+
if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
|
124
|
+
fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
|
125
|
+
end
|
126
|
+
|
127
|
+
# Are all source files checked in?
|
128
|
+
if ENV['RELTEST']
|
129
|
+
announce "Release Task Testing, skipping checked-in file test"
|
130
|
+
else
|
131
|
+
announce "Checking for unchecked-in files..."
|
132
|
+
data = `svn status`
|
133
|
+
unless data =~ /^$/
|
134
|
+
fail "svn status is not clean ... do you have unchecked-in files?"
|
135
|
+
end
|
136
|
+
announce "No outstanding checkins found ... OK"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
task :update_version => [:prerelease] do
|
141
|
+
if PKG_VERSION == CURRENT_VERSION && ! ENV['FORCE']
|
142
|
+
announce "No version change ... skipping version update"
|
143
|
+
else
|
144
|
+
announce "Updating #{PKG_Name} version to #{PKG_VERSION}"
|
145
|
+
version_rb = "lib/#{PKG_NAME}/#{PKG_NAME}_version.rb"
|
146
|
+
open(version_rb, "w") do |f|
|
147
|
+
f.puts "# DO NOT EDIT"
|
148
|
+
f.puts "# This file is auto-generated by build scripts."
|
149
|
+
f.puts "# See: rake update_version"
|
150
|
+
f.puts "module #{PKG_Name}"
|
151
|
+
f.puts " #{PKG_Name}Version = '#{PKG_VERSION}'"
|
152
|
+
f.puts "end"
|
153
|
+
end
|
154
|
+
if ENV['RELTEST']
|
155
|
+
announce "Release Task Testing, skipping commiting of new version"
|
156
|
+
else
|
157
|
+
sh %{svn commit -m "Updated to version #{PKG_VERSION}" #{version_rb}}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# FIX ME for SVN
|
163
|
+
task :tag => [:prerelease] do
|
164
|
+
reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
|
165
|
+
reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
|
166
|
+
announce "Tagging repo with [#{reltag}]"
|
167
|
+
if ENV['RELTEST']
|
168
|
+
announce "Release Task Testing, skipping repo tagging"
|
169
|
+
else
|
170
|
+
sh %{echo cvs tag #{reltag}}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# --------------------------------------------------------------------
|
175
|
+
# Create a task to build the RDOC documentation tree.
|
176
|
+
|
177
|
+
desc "Create the RDOC html files"
|
178
|
+
rd = Rake::RDocTask.new("rdoc") { |rdoc|
|
179
|
+
rdoc.rdoc_dir = 'html'
|
180
|
+
rdoc.title = "#{PKG_Name}"
|
181
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
182
|
+
rdoc.rdoc_files.include('README', 'TODO', 'Releases')
|
183
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
184
|
+
# rdoc.rdoc_files.include('test/**/*.rb')
|
185
|
+
}
|
186
|
+
|
187
|
+
file "html/index.html" => [:rdoc]
|
188
|
+
|
189
|
+
desc "Publish the RDOCs on RubyForge"
|
190
|
+
task :publish_rdoc => ["html/index.html"] do
|
191
|
+
# NOTE: This task assumes that you have an SSH alias setup for rubyforge.
|
192
|
+
mkdir_p "emptydir"
|
193
|
+
sh "scp -rq emptydir rubyforge:/var/www/gforge-projects/#{RUBY_FORGE_PROJECT}/rdoc"
|
194
|
+
sh "scp -rq html/* rubyforge:/var/www/gforge-projects/#{RUBY_FORGE_PROJECT}/rdoc"
|
195
|
+
rm_r "emptydir"
|
196
|
+
end
|
197
|
+
|
198
|
+
# Wiki Doc Targets
|
199
|
+
|
200
|
+
desc "Upload the Hieraki Data"
|
201
|
+
task :upload => [:upload_gemdoc]
|
202
|
+
|
203
|
+
task :upload_gemdoc => ['scripts/gemdoc.hieraki'] do
|
204
|
+
ruby %{scripts/upload_gemdoc.rb}
|
205
|
+
end
|
206
|
+
|
207
|
+
desc "Build the Hieraki documentation"
|
208
|
+
task :hieraki => ['scripts/gemdoc.hieraki', 'scripts/specdoc.hieraki']
|
209
|
+
|
210
|
+
file 'scripts/gemdoc.hieraki' => ['scripts/gemdoc.rb', 'scripts/gemdoc.data'] do
|
211
|
+
chdir('scripts') do
|
212
|
+
ruby %{-I../lib gemdoc.rb <gemdoc.data >gemdoc.hieraki}
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
file 'scripts/specdoc.hieraki' =>
|
217
|
+
['scripts/specdoc.rb', 'scripts/specdoc.data', 'scripts/specdoc.yaml'] do
|
218
|
+
chdir('scripts') do
|
219
|
+
ruby %{-I../lib specdoc.rb >specdoc.hieraki}
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Package tasks
|
224
|
+
|
225
|
+
PKG_FILES = FileList[
|
226
|
+
"Rakefile", "ChangeLog", "Releases", "TODO", "README",
|
227
|
+
# "setup.rb",
|
228
|
+
# "post-install.rb",
|
229
|
+
"bin/*",
|
230
|
+
"doc/*.css", "doc/*.rb",
|
231
|
+
"examples/**/*",
|
232
|
+
# "gemspecs/**/*",
|
233
|
+
"lib/**/*.rb",
|
234
|
+
# "pkgs/**/*",
|
235
|
+
"redist/*.gem",
|
236
|
+
"scripts/*.rb",
|
237
|
+
"test/**/*"
|
238
|
+
]
|
239
|
+
PKG_FILES.exclude(%r(^(test/temp|examples/.*/*.log)(/|$)))
|
240
|
+
|
241
|
+
Rake::PackageTask.new("package") do |p|
|
242
|
+
p.name = PKG_NAME
|
243
|
+
p.version = PKG_VERSION
|
244
|
+
p.need_tar = true
|
245
|
+
p.need_zip = true
|
246
|
+
p.package_files = PKG_FILES
|
247
|
+
end
|
248
|
+
|
249
|
+
Spec = Gem::Specification.new do |s|
|
250
|
+
s.name = PKG_NAME
|
251
|
+
s.version = PKG_VERSION
|
252
|
+
s.summary = "#{PKG_Name} GEM"
|
253
|
+
s.description = %{Currency models currencies, monetary values, foreign exchanges.
|
254
|
+
}
|
255
|
+
s.files = PKG_FILES.to_a
|
256
|
+
s.require_path = 'lib'
|
257
|
+
s.author = "Kurt Stephens"
|
258
|
+
s.email = "ruby-#{PKG_NAME}@umleta.com"
|
259
|
+
s.homepage = "http://#{PKG_NAME}.rubyforge.org"
|
260
|
+
s.rubyforge_project = "#{RUBY_FORGE_PROJECT}"
|
261
|
+
#s.bindir = "bin" # Use these for applications.
|
262
|
+
#s.executables = ["update_rubygems"]
|
263
|
+
certdir = ENV['CERT_DIR']
|
264
|
+
if certdir
|
265
|
+
s.signing_key = File.join(certdir, 'gem-umleta-private_key.pem')
|
266
|
+
s.cert_chain = [File.join(certdir, 'gem-umleta-public_cert.pem')]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
# Add console output about signing the Gem
|
271
|
+
file "pkg/#{Spec.full_name}.gem" do
|
272
|
+
puts "Signed with certificates in '#{ENV['CERT_DIR']}'" if ENV['CERT_DIR']
|
273
|
+
end
|
274
|
+
|
275
|
+
Rake::GemPackageTask.new(Spec) do |p| end
|
276
|
+
|
277
|
+
GEMSPEC = "pkg/#{PKG_NAME}.gemspec"
|
278
|
+
desc "Build the Gem spec file for the #{PKG_NAME} package"
|
279
|
+
task :gemspec => GEMSPEC
|
280
|
+
file "pkg/#{PKG_NAME}.gemspec" => ["pkg", "Rakefile"] do |t|
|
281
|
+
open(t.name, "w") do |f| f.puts Spec.to_yaml end
|
282
|
+
end
|
283
|
+
|
284
|
+
# Automated upload to rubyforge.org
|
285
|
+
PACKAGE_FILES = FileList["pkg/#{PKG_NAME}-#{PKG_VERSION}.*"]
|
286
|
+
task :upload_package do
|
287
|
+
# From activesuport/Rakefile,
|
288
|
+
# See: http://dev.rubyonrails.org/svn/rails/tags/rel_1-1-6/activesupport/Rakefile
|
289
|
+
`rubyforge login`
|
290
|
+
|
291
|
+
files = PACKAGE_FILES
|
292
|
+
files.each do |filename|
|
293
|
+
basename = File.basename(filename)
|
294
|
+
puts "Releasing #{basename}..."
|
295
|
+
|
296
|
+
release_command = "rubyforge add_release #{RUBY_FORGE_PROJECT} #{RUBY_FORGE_PROJECT} 'REL #{PKG_VERSION}' #{filename}"
|
297
|
+
puts release_command
|
298
|
+
system(release_command)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
desc "Install #{PKG_Name}"
|
304
|
+
task :install do
|
305
|
+
ruby 'install.rb'
|
306
|
+
end
|
307
|
+
|
308
|
+
# Run 'gem' (using local bin and lib directories).
|
309
|
+
# e.g.
|
310
|
+
# rake rungem -- install -r blahblah --test
|
311
|
+
|
312
|
+
desc "Run local 'gem'"
|
313
|
+
task :rungem do
|
314
|
+
ARGV.shift
|
315
|
+
exec "ruby -Ilib bin/gem #{ARGV.join(' ')}"
|
316
|
+
end
|
317
|
+
|
318
|
+
# Misc Tasks ---------------------------------------------------------
|
319
|
+
|
320
|
+
def egrep(pattern)
|
321
|
+
Dir['**/*.rb'].each do |fn|
|
322
|
+
count = 0
|
323
|
+
open(fn) do |f|
|
324
|
+
while line = f.gets
|
325
|
+
count += 1
|
326
|
+
if line =~ pattern
|
327
|
+
puts "#{fn}:#{count}:#{line}"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
desc "Look for TODO and FIXME tags in the code"
|
335
|
+
task :todo do
|
336
|
+
egrep /#.*(FIXME|TODO|TBD)/
|
337
|
+
end
|
338
|
+
|
339
|
+
desc "Look for Debugging print lines"
|
340
|
+
task :dbg do
|
341
|
+
egrep /\bDBG|\bbreakpoint\b/
|
342
|
+
end
|
343
|
+
|
344
|
+
desc "List all ruby files"
|
345
|
+
task :rubyfiles do
|
346
|
+
puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
|
347
|
+
puts Dir['bin/*'].reject { |fn| fn =~ /CVS|.svn|(~$)|(\.rb$)/ }
|
348
|
+
end
|
349
|
+
|
data/Releases
ADDED
data/TODO
ADDED
File without changes
|
data/examples/ex1.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require 'currency'
|
4
|
+
require 'currency/currency_exchange_test'
|
5
|
+
|
6
|
+
x = Currency::Money.new("1,203.43", 'USD')
|
7
|
+
|
8
|
+
puts x.to_s
|
9
|
+
puts (x * 10).to_s
|
10
|
+
puts (x * 33333).to_s
|
11
|
+
|
12
|
+
puts x.currency.code.inspect
|
13
|
+
|
data/examples/xe1.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require 'currency'
|
4
|
+
require 'currency/currency_exchange_xe'
|
5
|
+
|
6
|
+
ex = Currency::CurrencyExchangeXe.new()
|
7
|
+
|
8
|
+
puts ex.inspect
|
9
|
+
puts ex.parse_page_rates.inspect
|
10
|
+
|
11
|
+
usd = Currency::Money.new("1", 'USD')
|
12
|
+
|
13
|
+
puts "usd = #{usd}"
|
14
|
+
|
15
|
+
cad = usd.convert(:CAD)
|
16
|
+
puts "cad = #{cad}"
|
17
|
+
|
18
|
+
|
19
|
+
|
data/lib/currency.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
require 'currency/exception'
|
6
|
+
require 'currency/money'
|
7
|
+
require 'currency/currency_factory'
|
8
|
+
require 'currency/currency'
|
9
|
+
require 'currency/money'
|
10
|
+
require 'currency/exchange_rate'
|
11
|
+
require 'currency/currency_exchange'
|
12
|
+
require 'currency/core_extensions'
|
13
|
+
|