Class: Adder
Constant Summary
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary
Attributes included from BasicLogging
Class Method Summary collapse
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, #set_target
Class Method Details
.add(options) ⇒ Object
27 28 29 30 31 32 33 34 35 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 |
# File 'lib/adder.rb', line 27 def self::add() debug('options are ' << .to_s) if .file @@events_file = .file @@events_backup = File.dirname(@@events_file) << File::Separator << 'bak_' << File.basename(@@events_file) else error('To add events, you must name a file on the command-line. Aborting') exit false end if(!.event || !.year) 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 @level = $LOG_LEVEL if $LOG_LEVEL fields = [:event, :year, :background] debug('options are ' << .to_s) if [:event] && [:year] if ![:background] warn('Optional background information is missing') bg = '' else bg = .background end ev_def = "$events << [\"" << .event << "\", " << .year << ", \"" << bg << "\"]" debug('writing events-backup to ' << @@events_backup) File.open(@@events_backup, 'w+') {|bak| bak.write( File.read(@@events_file))} debug('adding new event to the list: ' << ev_def) File.open(@@events_file, 'a') {|evf| evf.puts(ev_def)} info('A new event has been added to ' << @@events_file << '.') else opts = .to_h.keys error('Option missing: ' << fields.each {|f| opts.delete(f) }.join(', ')) exit false end end |