Sha256: d926d81a04859f2895bca1772085a55ec5670e68c50e9a85d761a541aef079b0

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# 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"]
#
class FilePolice::BacklogFile

  attr_accessor :collection, :box, :folder, :name, :number, :errors

  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

  # Should match strings like ARC0001
  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

  # Should match strings like BX1
  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

  # Should match strings like FL1, OS2, or FL22b
  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

  # Sould be numbers only
  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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
file_police-0.1.4 lib/file_police/backlog_file.rb
file_police-0.1.3 lib/file_police/backlog_file.rb
file_police-0.1.2 lib/file_police/backlog_file.rb