Class: Adder
Constant Summary collapse
- @@log =
self::init_logger
Class Method Summary collapse
Methods included from Logging
init_logger, log_label=, log_level=, log_target=
Methods included from File_Checking
Class Method Details
.add(options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/adder.rb', line 36 def self::add() @log.debug('options are ' << .to_s) if .file @@events_file = .file @@events_backup = File.dirname(@@events_file) << File::Separator << 'bak_' << File.basename(@@events_file) else @log.error('To add events, you must name a file on the command-line. Aborting') exit false end if(!.event || !.year) @log.error("To add events, you must provide them on the command-line.\n\tPSE start the program with option -h or --help to see an option-overview.") exit false end @@log.level = $LOG_LEVEL if $LOG_LEVEL fields = [:event, :year, :background] @log.debug('options are ' << .to_s) if [:event] && [:year] if ![:background] @log.warn('Optional background information is missing') bg = '' else bg = .background end ev_def = "$events << [\"" << .event << "\", " << .year << ", \"" << bg << "\"]" @log.debug('writing events-backup to ' << @@events_backup) File.open(@@events_backup, 'w+') {|bak| bak.write( File.read(@@events_file))} @log.debug('adding new event to the list: ' << ev_def) File.open(@@events_file, 'a') {|evf| evf.puts(ev_def)} @log.info('A new event has been added to ' << @@events_file << '.') else opts = .to_h.keys @log.error('Option missing: ' << fields.each {|f| opts.delete(f) }.join(', ')) exit false end end |