Refactored some of the code to match Rubocop style guidelines; will need to create rubocop config to make the style better

This commit is contained in:
Gregory Ballantine 2022-08-31 01:22:39 -04:00
parent 4c3ea4ea87
commit bc799ff2cb
4 changed files with 76 additions and 73 deletions

View File

@ -1,5 +1,6 @@
require 'toml'
# Loads and handles the application configuration.
class Config
# class constructor
@ -16,7 +17,7 @@ class Config
value = @config
bits = path.split('.')
bits.each { |bit|
if (value.has_key?(bit))
if (value.key?(bit))
value = value[bit]
else
abort("Configuration value #{path} does exist.")

View File

@ -2,44 +2,45 @@ require_relative 'util.rb'
require 'fileutils'
# Handles anything pertaining to the video file repository.
class Repository
def initialize(path)
@basePath = path
@base_path = path
# create repository base directory
createDirectory(@basePath)
create_directory(@base_path)
# create sub-directories
subPaths = ['ingest', 'archive', 'output']
subPaths.each { |p|
createDirectory(File.join(@basePath, p))
sub_paths = ['ingest', 'archive', 'output']
sub_paths.each { |p|
create_directory(File.join(@base_path, p))
}
end
def searchIngest
def search_ingest
# create our ingest directory path
ingestPath = File.join(@basePath, 'ingest')
ingest_path = File.join(@base_path, 'ingest')
# search for files in ingest; ignore non-files (e.g. directories)
ingestFiles = Dir.entries(ingestPath).select { |f| File.file? File.join(ingestPath, f) }
ingest_files = Dir.entries(ingest_path).select { |f| File.file? File.join(ingest_path, f) }
return ingestFiles
return ingest_files
end
def archiveFile(filename)
def archive_file(filename)
# create source and destination paths for the copy
ingestPath = File.join(@basePath, 'ingest', filename)
archivePath = File.join(@basePath, 'archive', filename)
ingest_path = File.join(@base_path, 'ingest', filename)
archive_path = File.join(@base_path, 'archive', filename)
# perform the copy, preserving file attributes
FileUtils.cp(ingestPath, archivePath, preserve: true)
FileUtils.cp(ingest_path, archive_path, preserve: true)
end
def cleanupFile(filename)
def cleanup_file(filename)
# create ingest path
ingestPath = File.join(@basePath, 'ingest', filename)
ingest_path = File.join(@base_path, 'ingest', filename)
# remove the file
FileUtils.remove_file(ingestPath)
FileUtils.remove_file(ingest_path)
end
end

View File

@ -1,3 +1,4 @@
# Handles the actual transcoding.
class Transcoder
def initialize(config, repository)
@ -6,17 +7,17 @@ class Transcoder
end
def start
puts "Starting transcoder..."
puts 'Starting transcoder...'
# search for files in ingest
ingestFiles = @repository.searchIngest()
ingestFiles.each { |ifile|
ingest_files = @repository.search_ingest()
ingest_files.each { |ifile|
# archive the file
@repository.archiveFile(ifile)
@repository.archive_file(ifile)
# perform the transcode
# // TODO self.transcode(ifile)
# clean up the file from ingest
@repository.cleanupFile(ifile)
@repository.cleanup_file(ifile)
}
end

View File

@ -1,5 +1,5 @@
def createDirectory(path)
if Dir.exists?(path)
def create_directory(path)
if Dir.exist?(path)
puts "Directory #{path} already exists."
else
puts "Creating directory #{path}."