class FilePolice::BacklogFile
Checks the name of a file in our backlog for proper format.
Ex. > good = BacklogFile.new(filepath)
> good.errors
> []¶ ↑
> bad = BacklogFile.new(filepath)
> bad.errors
> [“This is bad”, “That is bad”]¶ ↑
Attributes
box[RW]
collection[RW]
errors[RW]
folder[RW]
name[RW]
number[RW]
Public Class Methods
new(path)
click to toggle source
# File lib/file_police/backlog_file.rb, line 15 def initialize path parts = File.basename(path, File.extname(path)).split("_") self.errors = Array.new if parts.length == 5 validate_collection(parts[0]) validate_box(parts[1]) validate_folder(parts[2]) self.name = parts[3] validate_number(parts[4]) else self.errors << "Filename does not have 5 segments separated by underscores (_)" end end
Public Instance Methods
validate_box(box = String.new)
click to toggle source
Should match strings like BX1
# File lib/file_police/backlog_file.rb, line 36 def validate_box box = String.new self.errors << "#{box} does not have the correct format" unless box.match(/^[A-Z]{2,2}[0-9]{1,3}$/) self.box = box end
validate_collection(collection = String.new)
click to toggle source
Should match strings like ARC0001
# File lib/file_police/backlog_file.rb, line 30 def validate_collection collection = String.new self.errors << "#{collection} does not match ARC#### format" unless collection.match(/^ARC[0-9]{4,4}$/) self.collection = collection end
validate_folder(folder = String.new)
click to toggle source
Should match strings like FL1, OS2, or FL22b
# File lib/file_police/backlog_file.rb, line 42 def validate_folder folder = String.new self.errors << "#{folder} does not have the correct format" unless folder.match(/^[A-Z]{2,2}[0-9]{1,3}[a-z]{0,1}$/) self.folder = folder end
validate_number(number = String.new)
click to toggle source
Sould be numbers only
# File lib/file_police/backlog_file.rb, line 48 def validate_number number = String.new self.errors << "#{number} does not have the correct format" unless number.match(/^[0-9]{1,4}[a-z]{0,1}$/) self.number = number end