-
Notifications
You must be signed in to change notification settings - Fork 2
/
gleaner.rb
35 lines (33 loc) · 1013 Bytes
/
gleaner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Gleaner
def self.site_from_filename filename
if File.basename(filename) =~ /\Asam/
match = File.basename(filename).match(/\Asam(?: ?(\d+[a-z]?)|_(tnc_\d+))/)
if match.nil?
STDERR.puts "Unable to glean site from filename #{filename}."
exit(1)
end
site = match[1] || match[2]
site.sub(/\A0/,"").gsub("_", " ")
else
match = File.basename(filename).match(/(?:\Asite (\d+[a-z]?)|(\Atnc \d+))/)
if match.nil?
STDERR.puts "Unable to glean site from filename #{filename}."
exit(1)
end
site = match[1] || match[2]
site.sub(/\A0/,"").gsub("_", " ")
end
end
def self.year_from_filename filename
if File.basename(filename) =~ /\Asam/
year = "2011"
else
match = File.basename(filename).match(/\A(?:site|tnc) \d+[a-z]? (\d\d\d\d)/)
if match.nil?
STDERR.puts "Unable to glean year from filename #{filename}."
exit(1)
end
year = match[1]
end
end
end