banking_data 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/banking_data/bank.rb +15 -1
- data/lib/banking_data/version.rb +1 -1
- data/spec/banking_data/german_bank_spec.rb +8 -0
- metadata +2 -2
data/lib/banking_data/bank.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module BankingData
|
2
2
|
class Bank
|
3
3
|
|
4
|
+
@@options = {}
|
5
|
+
|
4
6
|
# goal: do something like:
|
5
7
|
# BankingData::Bank.where(locale: :de).only(:bic)
|
6
8
|
def self.where(options = {})
|
@@ -11,13 +13,25 @@ module BankingData
|
|
11
13
|
AustrianBank.where(options)
|
12
14
|
elsif locale == 'CH' || locale == :ch
|
13
15
|
SwissBank.where(options)
|
16
|
+
elsif options.empty?
|
17
|
+
self
|
14
18
|
else
|
19
|
+
@@options = @@options.merge(options)
|
15
20
|
self
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
24
|
def self.only(*attributes)
|
20
|
-
|
25
|
+
options = @@options
|
26
|
+
@@options = {}
|
27
|
+
all.select { |bank| options.map { |k, v| bank.send(k) == v }.all? }
|
28
|
+
.map { |bank| attributes.map { |attr| bank.send(attr) } }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.to_a
|
32
|
+
options = @@options
|
33
|
+
@@options = {}
|
34
|
+
all.select { |bank| options.map { |k, v| bank.send(k) == v }.all? }
|
21
35
|
end
|
22
36
|
end
|
23
37
|
end
|
data/lib/banking_data/version.rb
CHANGED
@@ -6,6 +6,14 @@ module BankingData
|
|
6
6
|
['MARKDEF1100', 'PBNKDEFF100'].each do |bic|
|
7
7
|
it "includes #{bic}" do
|
8
8
|
expect(GermanBank.only(:bic).map(&:first)).to include(bic)
|
9
|
+
expect(Bank.where(locale: :de).only(:bic).map(&:first))
|
10
|
+
.to include(bic)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
['76350000', '37040044'].each do |blz|
|
14
|
+
it "includes #{blz}" do
|
15
|
+
expect(GermanBank.only(:blz).map(&:first)).to include(blz)
|
16
|
+
expect(Bank.where(locale: :de, blz: blz).only(:blz).first).to eq([blz])
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banking_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2013-10-
|
12
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|