Class: CronWTF::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Entry

Returns a new instance of Entry.



4
5
6
7
8
# File 'lib/rcronwtf/entry.rb', line 4

def initialize(entry)
  @is_comment = (entry.nil? or entry.strip.empty? or entry.match /^#/) ? true : false
  @entry = entry.strip.gsub(/\s+/, " ")
  parse unless is_comment
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def command
  @command
end

#daysObject (readonly)

Returns the value of attribute days.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def hours
  @hours
end

#is_commentObject (readonly)

Returns the value of attribute is_comment.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def is_comment
  @is_comment
end

#minutesObject (readonly)

Returns the value of attribute minutes.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def months
  @months
end

#week_daysObject (readonly)

Returns the value of attribute week_days.



2
3
4
# File 'lib/rcronwtf/entry.rb', line 2

def week_days
  @week_days
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rcronwtf/entry.rb', line 10

def to_s
  return @entry if is_comment
  
  msg = []

  %w(minute hour day month week_day).each do |attribute|
    key = (attribute + "s")
    prev = msg[msg.length - 1]
    values = self.send(key)

    if(values == '*')
      if(!prev || !prev.match(/^every/))
        msg << "every #{attribute.gsub('_', ' ')}"
      end
    else
      msg << send("#{key}_message", values)
    end
  end

  "Runs `#{@command}` #{msg.join(', ')}."
end