Class: CronVariable

Inherits:
Hash
  • Object
show all
Defined in:
lib/khronotab/cron_variable.rb

Constant Summary collapse

VAR_REGEX =
%r{(^\s*[^#]\w+)=(.+)}i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CronVariable

Returns a new instance of CronVariable.



27
28
29
30
# File 'lib/khronotab/cron_variable.rb', line 27

def initialize(data)
  @name = data[:name]
  @value = data[:value]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/khronotab/cron_variable.rb', line 3

def name
  @name
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/khronotab/cron_variable.rb', line 3

def value
  @value
end

Class Method Details

.add_new(cron_entry) ⇒ Object



21
22
23
24
25
# File 'lib/khronotab/cron_variable.rb', line 21

def self.add_new(cron_entry)
  return nil unless VAR_REGEX.match(cron_entry)
  name, value = cron_entry.scan(VAR_REGEX).shift
  self.new( :name => name, :value => value )
end

.matches?(cron_entry) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/khronotab/cron_variable.rb', line 17

def self.matches?(cron_entry)
  !!VAR_REGEX.match(cron_entry)
end

Instance Method Details

#[](ac) ⇒ Object



7
8
9
10
# File 'lib/khronotab/cron_variable.rb', line 7

def [](ac)
  return self.send(ac) if self.respond_to?(ac)
  raise 'Unknown key!'
end

#[]=(key, value) ⇒ Object



12
13
14
15
# File 'lib/khronotab/cron_variable.rb', line 12

def []=(key,value)
  return self.send("#{key}=", value) if self.respond_to?(key)
  raise 'Unknown key!'
end

#to_lineObject



37
38
39
# File 'lib/khronotab/cron_variable.rb', line 37

def to_line
  puts "%s=%s" % [ self.name, self.values ]
end

#to_sObject



32
33
34
35
# File 'lib/khronotab/cron_variable.rb', line 32

def to_s
  puts "< CronVariable name: %s, value: '%s' >" %
           [ self.name, self.value ]
end