Module: BLZ

Defined in:
lib/blz.rb,
lib/blz/bank.rb

Defined Under Namespace

Classes: Bank

Constant Summary collapse

DATA_FILE =
find_data_file

Class Method Summary collapse

Class Method Details

.find_data_file(now = Date.today) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/blz.rb', line 13

def self.find_data_file(now=Date.today)
  glob = Dir[ File.join(File.dirname(__FILE__), '../data/*.tsv.gz') ].sort

  file2time = proc do |f|
    match = f.match /(?<y>\d{4})_(?<m>\d\d)_(?<d>\d\d)\.tsv\.gz$/
    Date.new match[:y].to_i, match[:m].to_i, match[:d].to_i
  end

  filename = glob.find {|c| now <= file2time[c] } || glob.last

  # sanity check
  t = file2time[filename]
  if t < Date.new(2013, 12, 9) || now > t + 90
    warn '[BLZ] The data provided may not be accurate.'
  end

  filename
end