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

error(msg = nil, code = nil) click to toggle source

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
execute() click to toggle source

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
extractor_details() click to toggle source

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
extractors() click to toggle source

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
list_fields() click to toggle source

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
logger() click to toggle source

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
reader() click to toggle source

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
time_period(time_period_s) click to toggle source

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
write_file() click to toggle source

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