Class: CronEdit::CronEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/cronedit.rb

Overview

A cron entry …

Defined Under Namespace

Classes: FormatError

Constant Summary collapse

DEFAULTS =
{
    :minute => '*',
    :hour => '*',
    :day => '*',
    :month => '*',
    :weekday => '*',
    :command => ''
}

Instance Method Summary collapse

Constructor Details

#initialize(aDef = {}) ⇒ CronEntry

Hash def, or raw String def



421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/cronedit.rb', line 421

def initialize aDef = {}
    if aDef.kind_of? Hash  
        wrong = aDef.collect { |k,v| DEFAULTS.include?(k) ? nil : k}.compact
        raise "Wrong definition, invalid constructs #{wrong}" unless wrong.empty?
        @defHash = DEFAULTS.merge aDef
        # TODO: validate values
        @def = to_raw @defHash ;
    else
        @defHash = parseTextDef aDef
        @def = aDef;
    end
end

Instance Method Details

#[](aField) ⇒ Object



442
443
444
# File 'lib/cronedit.rb', line 442

def []aField
    @defHash[aField]
end

#to_hashObject



438
439
440
# File 'lib/cronedit.rb', line 438

def to_hash
    @defHash.freeze
end

#to_raw(aHash = nil) ⇒ Object



446
447
448
449
450
# File 'lib/cronedit.rb', line 446

def to_raw aHash = nil;
    aHash ||= @defHash
    "#{aHash[:minute]}\t#{aHash[:hour]}\t#{aHash[:day]}\t#{aHash[:month]}\t"  +
        "#{aHash[:weekday]}\t#{aHash[:command]}"
end

#to_sObject



434
435
436
# File 'lib/cronedit.rb', line 434

def to_s
    @def.freeze
end