Class: FilePolice::BacklogFile

Inherits:
Object
  • Object
show all
Defined in:
lib/file_police/backlog_file.rb

Overview

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”]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ BacklogFile

Returns a new instance of BacklogFile.



15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#boxObject

Returns the value of attribute box.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def box
  @box
end

#collectionObject

Returns the value of attribute collection.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def collection
  @collection
end

#errorsObject

Returns the value of attribute errors.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def errors
  @errors
end

#folderObject

Returns the value of attribute folder.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def folder
  @folder
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def name
  @name
end

#numberObject

Returns the value of attribute number.



13
14
15
# File 'lib/file_police/backlog_file.rb', line 13

def number
  @number
end

Instance Method Details

#validate_box(box = String.new) ⇒ Object

Should match strings like BX1



36
37
38
39
# 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) ⇒ Object

Should match strings like ARC0001



30
31
32
33
# 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) ⇒ Object

Should match strings like FL1, OS2, or FL22b



42
43
44
45
# 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) ⇒ Object

Sould be numbers only



48
49
50
51
# 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