blz 0.1.4.20170306 → 0.2.0.20170605

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b91975870ed8a957ec0b85731e5688934b48729
4
- data.tar.gz: 181e78ea59318c93deeefdf3998a79a1ceb49f96
3
+ metadata.gz: 583b483d338385dc57d528a92908249de42bcb29
4
+ data.tar.gz: e3e9638f159ef7b87e083021ca86e40a0e5b3603
5
5
  SHA512:
6
- metadata.gz: 6b1eeb84ce1631d0fd739795be6a3104de50864c2ef9195597c427bb08728ae708aa3f935f427fa687bcce0d3aab5ff4ac29dc98b99d0eb6abd6d60f7d32dff5
7
- data.tar.gz: '0664556387efcb42313cd0ca50c641ad8408707ffd0dd59d6d3830521fbced644e9f42f227d845904c6683aa7ddc62f62eb567f2fe05526b966ab69ce68f4347'
6
+ metadata.gz: 75a886ea53fa801e1832b2564cfa0ecf1ba3a4308a40b19bac7c9c221b24c2b668a4d271976d4983b1e94292a5c4e92a3dbdeb32a52d41913d626e407d08959e
7
+ data.tar.gz: bc03dd1c2d3bd6dc73956c03d764730996e1f5b1fad95bb6ebbdb43be1985a740ca7d03e3767998b995e190041a87c0ab3325a5ee6ee42ca3a21140f19378970
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.2.0.20170605, released 2017-05-08
2
+
3
+ * BLZ data file for cycle 2017-06-04 to 2017-09-03 added
4
+ * BLZ data files for 2015 removed
5
+ * revamped tests, so that manual editing becomes unnecessary
6
+
1
7
  # 0.1.4.20170306, released 2017-02-06
2
8
 
3
9
  * BLZ data file for cycle 2017-03-06 to 2017-06-04 added
data/README.md CHANGED
@@ -78,10 +78,7 @@ files. Currently, this is a 3-monthly manual process of:
78
78
  3. Gzip'ing the `.tsv` file (i.e. `gzip -9 yyyy_mm_dd.tsv`, resulting
79
79
  in `data/yyyy_mm_dd.tsv.gz`).
80
80
 
81
- 4. Modify the `test_current_data_file` method in `test/test_bank.rb` to
82
- reflect the latest file.
83
-
84
- 5. Run the tests (`rake`).
81
+ 4. Run the tests (`rake`).
85
82
 
86
83
  Obviously, this process tends to be error prone. A pull request with a
87
84
  Rake task completing these steps would be nice to have.
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.20170306'
7
+ s.version = '0.2.0.20170605'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.summary = "BLZ (Bankleitzahlen) for Ruby"
10
10
 
Binary file
data/lib/blz.rb CHANGED
@@ -10,23 +10,22 @@
10
10
  require "date"
11
11
 
12
12
  module BLZ
13
+ def self.convert_file_to_date(f)
14
+ match = f.match /(?<y>\d{4})_(?<m>\d\d)_(?<d>\d\d)\.tsv\.gz$/
15
+ Date.new match[:y].to_i, match[:m].to_i, match[:d].to_i
16
+ end
17
+
13
18
  def self.find_data_file(now=Date.today)
14
19
  glob = Dir[ File.join(File.dirname(__FILE__), '../data/*.tsv.gz') ].sort
15
-
16
- file2time = proc do |f|
17
- match = f.match /(?<y>\d{4})_(?<m>\d\d)_(?<d>\d\d)\.tsv\.gz$/
18
- Date.new match[:y].to_i, match[:m].to_i, match[:d].to_i
19
- end
20
-
21
- filename = glob.find {|c| now <= file2time[c] } || glob.last
20
+ file = glob.find {|c| now <= convert_file_to_date(c) } || glob.last
22
21
 
23
22
  # sanity check
24
- t = file2time[filename]
25
- if t < Date.new(2013, 12, 9) || now > t + 90
23
+ if now < Date.new(2016, 3, 6) || now > (convert_file_to_date(file) + 90)
24
+ warn [now]
26
25
  warn '[BLZ] The data provided may not be accurate.'
27
26
  end
28
27
 
29
- filename
28
+ file
30
29
  end
31
30
 
32
31
  DATA_FILE = find_data_file
data/test/test_bank.rb CHANGED
@@ -2,26 +2,36 @@
2
2
 
3
3
  require 'blz'
4
4
  require 'test/unit'
5
+ require 'stringio'
5
6
 
6
7
  class TestBank < Test::Unit::TestCase
8
+ DATA_FILES = Dir[File.join(File.dirname(__FILE__), '../data/*.tsv.gz')].sort
9
+
10
+ DATA_FILES.each do |filename|
11
+ define_method "test_find_file_for_#{File.basename(filename)[0..-8]}" do
12
+ assert_stderr_no_match "The data provided may not be accurate" do
13
+ date = BLZ.convert_file_to_date(filename)
14
+ file = BLZ.find_data_file(date)
15
+ assert_equal b(filename), b(file)
16
+ end
17
+ end
18
+ end
7
19
 
8
- def test_data_file_finder
9
- {
10
- Date.new(2000,1,1) => "2015_03_09.tsv.gz",
11
- Date.new(2015,1,1) => "2015_03_09.tsv.gz",
12
- Date.new(2015,3,9) => "2015_03_09.tsv.gz",
13
-
14
- Date.new(2015,3,10) => "2015_12_06.tsv.gz",
15
- Date.new(2015,6,25) => "2015_12_06.tsv.gz",
16
- Date.new(2015,12,6) => "2015_12_06.tsv.gz",
17
-
18
- Date.new(2015,12,7) => "2016_03_06.tsv.gz",
19
- Date.new(2016,3,6) => "2016_03_06.tsv.gz",
20
- Date.new(2016,3,7) => "2016_09_04.tsv.gz",
21
- Date.new(2017,6,5) => "2017_03_06.tsv.gz", # ! until next release cycle
22
- }.each do |date, filename|
23
- file = BLZ.find_data_file(date)
24
- assert_equal filename, File.basename(file)
20
+ def test_find_file_for_past_date
21
+ assert_stderr_match "The data provided may not be accurate" do
22
+ file = DATA_FILES.first
23
+ date = BLZ.convert_file_to_date(file) - 1
24
+ found = BLZ.find_data_file(date)
25
+ assert_equal b(file), b(found)
26
+ end
27
+ end
28
+
29
+ def test_find_file_for_future_date
30
+ assert_stderr_match "The data provided may not be accurate" do
31
+ file = DATA_FILES.last
32
+ date = BLZ.convert_file_to_date(file) + 91
33
+ found = BLZ.find_data_file(date)
34
+ assert_equal b(file), b(found)
25
35
  end
26
36
  end
27
37
 
@@ -91,4 +101,29 @@ class TestBank < Test::Unit::TestCase
91
101
  assert_equal "70150000, Stadtsparkasse München, 80791 München, SSKMDEMMXXX", results[0].to_s
92
102
  end
93
103
 
104
+ # helper
105
+
106
+ def assert_stderr_match(msg, &block)
107
+ serr = redirect_stderr(&block)
108
+ assert_match msg, serr
109
+ end
110
+
111
+ def assert_stderr_no_match(msg, &block)
112
+ msg = Regexp.new(Regexp.escape(msg)) unless msg.is_a?(Regexp)
113
+ serr = redirect_stderr(&block)
114
+ assert_no_match msg, serr
115
+ end
116
+
117
+ def b(file)
118
+ File.basename file
119
+ end
120
+
121
+ def redirect_stderr
122
+ fake_stderr = StringIO.new
123
+ original_stderr, $stderr = $stderr, fake_stderr
124
+ yield
125
+ fake_stderr.string
126
+ ensure
127
+ $stderr = original_stderr
128
+ end
94
129
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.20170306
4
+ version: 0.2.0.20170605
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Eilhard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-06 00:00:00.000000000 Z
12
+ date: 2017-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -78,11 +78,10 @@ files:
78
78
  - Rakefile
79
79
  - bin/blz
80
80
  - blz.gemspec
81
- - data/2015_03_09.tsv.gz
82
- - data/2015_12_06.tsv.gz
83
81
  - data/2016_03_06.tsv.gz
84
82
  - data/2016_09_04.tsv.gz
85
83
  - data/2017_03_06.tsv.gz
84
+ - data/2017_06_05.tsv.gz
86
85
  - lib/blz.rb
87
86
  - lib/blz/bank.rb
88
87
  - test/test_bank.rb
Binary file
Binary file