class AlmaCourseLoader::CLI::CourseLoader
The abstract base class for course loader command line processing @abstract Loader implementations should subclass this class and implement
the #extractors, #reader and #time_period methods
Constants
- EXIT_OK
Exit codes
Public Instance Methods
Displays an error message and exits @param msg [String, nil] the error message @param code [Integer] the exit code - do not exit if nil @return [void]
# File lib/alma_course_loader/cli/course_loader.rb, line 54 def error(msg = nil, code = nil) STDERR.puts(msg) if msg exit(code) if code end
Clamp entry point - executes the command @return [void]
# File lib/alma_course_loader/cli/course_loader.rb, line 77 def execute # List the available field extractors and exit if required list_fields if fields? # Otherwise write a course loader file and exit write_file end
Returns a hash of named field value extractor descriptions. Keys correspond to the keys of the extractors hash, values should be short descriptions of each field extractor. @abstract Subclasses should implement this method @return [Hash<String|Symbol, String>] the field extractor descriptions
# File lib/alma_course_loader/cli/course_loader.rb, line 64 def extractor_details nil end
Returns a hash of named field value extractors @abstract Subclasses must implement this method @return [Hash<String|Symbol, Method|Proc>] the field extractors
# File lib/alma_course_loader/cli/course_loader.rb, line 71 def extractors raise NotImplementedError end
Lists the available field extractors and exits @return [void]
# File lib/alma_course_loader/cli/course_loader.rb, line 86 def list_fields d = extractor_details || {} extractors.each_key { |k| puts "#{k}#{d[k] ? ': ' : ''}#{d[k] || ''}" } exit(EXIT_OK) end
Creates a Logger instance @return [Logger] the Logger instance
# File lib/alma_course_loader/cli/course_loader.rb, line 94 def logger return nil unless log_file logger = Logger.new(log_file) logger.level = log_level logger end
Creates a Reader
instance to retrieve course data @abstract Subclasses must implement this method.
Filters are defined in the filter_list array: MyReader.new(..., filters: filter_list)
@return [AlmaCourseLoader::Reader] a subclass of Reader
# File lib/alma_course_loader/cli/course_loader.rb, line 106 def reader raise NotImplementedError end
Parses a time period string and returns an appropriate representation @abstract Subclasses may implement this method @param time_period_s [String] the time period string @return [Object] the subclass-specific representation of the time period
# File lib/alma_course_loader/cli/course_loader.rb, line 114 def time_period(time_period_s) time_period_s end
Writes an Alma course loader file and exits @return [void]
# File lib/alma_course_loader/cli/course_loader.rb, line 120 def write_file op = if rollover? :rollover elsif delete? :delete else :update end Dotenv.load(env_file) unless env_file.nil? || env_file.empty? AlmaCourseLoader::Writer.write(out_file, op, reader) exit(EXIT_OK) end