blz 0.1.4.20140907.1 → 0.1.4.20140907.2

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: c92ba1e85bfb29f54aa927bfed7c67711cbb2c30
4
- data.tar.gz: ece9e41ea54f2d17311b10d2133556b1ae01f54a
3
+ metadata.gz: dcc624f8a1d94f6442eeca3cc87fc50159bf2915
4
+ data.tar.gz: 4aaa942082b94a7d76dd6cedd970ae133af8067d
5
5
  SHA512:
6
- metadata.gz: de5fb1a8059494dcad8488e4d95901973fe3a9e457aa41c2740eebeac8b202ab3455ede3254bd1640bcdd434816cbde170be03a4a6f53c38fa9cd227bac07cdd
7
- data.tar.gz: 0593c80481b54d1b1cd4f3c8c297c02da09d3ba2231a74d2c1bb5ab6567c9886d734d3aeb59336cf01d5d2ed5039d18ecacaa0341aa876e3ce5fb78924c73b21
6
+ metadata.gz: 112044c5a3cd5df8c4a8e26d7d11f76d0e57e8710b6bf51e398d3832904f450eedf0defe2cbb988a525498da8da2a3b6c8a8bb2784eb840ee24dbc972d2b669b
7
+ data.tar.gz: b68b0f12573d8ae07d755f0b7c0b20fa3dcd837ab82adca8657a61c71193863fae447aa971fe84fb091ed9f7c844eed9dfe9d391fccdf6dc65f3f25f1de2e5ba
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- # 0.1.4.20140907a, released 2014-07-11
1
+ # 0.1.4.20140907.2, released 2014-07-25
2
+
3
+ * finders return an empty array when given `nil` or a blank string
4
+
5
+ # 0.1.4.20140907.1, released 2014-07-11
2
6
 
3
7
  * apply update BIC of Sberbank (SEZBDEF1XXX → SEZDDEF1XXX)
4
8
  after Bundesbank ExtraNet notifcation from 2014-07-10
data/blz.gemspec CHANGED
@@ -4,7 +4,7 @@ extra_rdoc_files = ['CHANGELOG.md', 'LICENSE', 'README.md']
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'blz'
7
- s.version = '0.1.4.20140907.1'
7
+ s.version = '0.1.4.20140907.2'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.summary = "BLZ (Bankleitzahlen) for Ruby"
10
10
 
data/lib/blz/bank.rb CHANGED
@@ -11,6 +11,8 @@ module BLZ
11
11
  # exact:: Only return exact matches (false by default)
12
12
  #
13
13
  def find_by_blz(code, options = {})
14
+ return [] if blank?(code)
15
+
14
16
  exact = options.fetch(:exact, false)
15
17
  all.select do |bank|
16
18
  bank.blz == code || (!exact && bank.blz.start_with?(code))
@@ -19,6 +21,8 @@ module BLZ
19
21
 
20
22
  # Returns an array of all Banks with a substring of +city+.
21
23
  def find_by_city(substring)
24
+ return [] if blank?(substring)
25
+
22
26
  all.select do |bank|
23
27
  bank.city.index(substring)
24
28
  end
@@ -29,6 +33,8 @@ module BLZ
29
33
  # exact:: Only return exact matches (false by default)
30
34
  #
31
35
  def find_by_bic(bic, options = {})
36
+ return [] if blank?(bic)
37
+
32
38
  exact = options.fetch(:exact, false)
33
39
  all.select do |bank|
34
40
  bank.bic == bic || (!exact && (bank.bic || '').start_with?(bic))
@@ -51,6 +57,18 @@ module BLZ
51
57
  end
52
58
  banks
53
59
  end
60
+
61
+ # Checks whether an object is blank (empty Array/Hash/String).
62
+ #
63
+ # Does not rely on ActiveSupport, but prefers that implementation.
64
+ def blank?(obj)
65
+ return true if obj.nil?
66
+ return obj.blank? if obj.respond_to?(:blank?)
67
+ obj = obj.strip if String === obj
68
+ return obj.empty? if obj.respond_to?(:empty?)
69
+
70
+ false
71
+ end
54
72
  end
55
73
 
56
74
  attr_reader :blz, :name, :zip, :city, :short_name, :bic
@@ -69,5 +87,6 @@ module BLZ
69
87
  def to_s
70
88
  [blz, name, "#{zip} #{city}", bic].compact.reject(&:empty?).join(', ')
71
89
  end
90
+
72
91
  end
73
92
  end
data/test/test_bank.rb CHANGED
@@ -51,6 +51,16 @@ class TestBank < Test::Unit::TestCase
51
51
  assert results.find { |b| b.blz == "70150000" }
52
52
  end
53
53
 
54
+ def test_search_by_empty_bic
55
+ assert results = BLZ::Bank.find_by_bic('')
56
+ assert results.size == 0
57
+ end
58
+
59
+ def test_search_by_nil_bic
60
+ assert results = BLZ::Bank.find_by_bic(nil)
61
+ assert results.size == 0
62
+ end
63
+
54
64
  def test_to_s
55
65
  assert results = BLZ::Bank.find_by_blz("70150000", :exact_only => true)
56
66
  assert_equal 1, results.size
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.20140907.1
4
+ version: 0.1.4.20140907.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Eilhard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler