latinum 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -2
- data/lib/latinum/collection.rb +23 -1
- data/lib/latinum/version.rb +1 -1
- data/test/test_collection.rb +17 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -43,8 +43,7 @@ To add multiple currencies together, use a collection:
|
|
43
43
|
|
44
44
|
> currencies = Set.new
|
45
45
|
> collection = Latinum::Collection.new(currencies)
|
46
|
-
> collection << ten
|
47
|
-
> collection << twenty
|
46
|
+
> collection << [ten, twenty]
|
48
47
|
> currencies.collect {|currency| collection[currency]}
|
49
48
|
=> [10.0 NZD, 20.0 AUD]
|
50
49
|
|
data/lib/latinum/collection.rb
CHANGED
@@ -31,12 +31,34 @@ module Latinum
|
|
31
31
|
attr :names
|
32
32
|
attr :resources
|
33
33
|
|
34
|
-
def
|
34
|
+
def add resource
|
35
35
|
@resources[resource.name] += resource.amount
|
36
|
+
end
|
37
|
+
|
38
|
+
def << object
|
39
|
+
case object
|
40
|
+
when Resource
|
41
|
+
add(object)
|
42
|
+
when Array
|
43
|
+
object.each { |resource| add(resource) }
|
44
|
+
when Collection
|
45
|
+
object.resources.each { |name, amount| @resources[name] += amount }
|
46
|
+
end
|
36
47
|
|
37
48
|
return self
|
38
49
|
end
|
39
50
|
|
51
|
+
def others
|
52
|
+
self.dup
|
53
|
+
|
54
|
+
case others
|
55
|
+
when Array
|
56
|
+
others.each { |resource| self << resource }
|
57
|
+
when Collection
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
40
62
|
def [] key
|
41
63
|
Resource.new(@resources[key], key)
|
42
64
|
end
|
data/lib/latinum/version.rb
CHANGED
data/test/test_collection.rb
CHANGED
@@ -24,4 +24,21 @@ class CollectionTest < Test::Unit::TestCase
|
|
24
24
|
collection << resource
|
25
25
|
assert_equal resource * 2, collection["NZD"]
|
26
26
|
end
|
27
|
+
|
28
|
+
def test_additions
|
29
|
+
resources = [
|
30
|
+
Latinum::Resource.new("10", "NZD"),
|
31
|
+
Latinum::Resource.new("10", "AUD"),
|
32
|
+
Latinum::Resource.new("10", "USD"),
|
33
|
+
Latinum::Resource.new("10", "NZD"),
|
34
|
+
Latinum::Resource.new("10", "AUD"),
|
35
|
+
Latinum::Resource.new("10", "USD")
|
36
|
+
]
|
37
|
+
|
38
|
+
collection = Latinum::Collection.new
|
39
|
+
collection << resources
|
40
|
+
|
41
|
+
assert_equal resources[0] * 2, collection["NZD"]
|
42
|
+
assert_equal Set.new(["NZD", "AUD", "USD"]), collection.names
|
43
|
+
end
|
27
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: samuel.williams@oriontransfer.co.nz
|