Class: Rekiq::Contract

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/rekiq/contract.rb

Constant Summary

Constants included from Validator

Validator::NUMERIC_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validator

included, #validate!, #validate_bool!, #validate_numeric!, #validate_schedule!

Constructor Details

#initialize(attributes = {}) ⇒ Contract

Returns a new instance of Contract.



30
31
32
33
34
35
36
37
38
# File 'lib/rekiq/contract.rb', line 30

def initialize(attributes = {})
  @schedule            = attributes['schedule']
  @cancel_args         = attributes['cancel_args']
  @addon               = attributes['addon']
  @schedule_post_work  = attributes['schedule_post_work']
  @work_time_shift     = attributes['work_time_shift']
  @work_time_tolerance = attributes['work_time_tolerance']
  @schedule_expired    = attributes['schedule_expired']
end

Instance Attribute Details

#addonObject

Returns the value of attribute addon.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def addon
  @addon
end

#cancel_argsObject

Returns the value of attribute cancel_args.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def cancel_args
  @cancel_args
end

#scheduleObject

Returns the value of attribute schedule.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def schedule
  @schedule
end

#schedule_expiredObject

Returns the value of attribute schedule_expired.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def schedule_expired
  @schedule_expired
end

#schedule_post_workObject

Returns the value of attribute schedule_post_work.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def schedule_post_work
  @schedule_post_work
end

#work_time_shiftObject

Returns the value of attribute work_time_shift.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def work_time_shift
  @work_time_shift
end

#work_time_toleranceObject

Returns the value of attribute work_time_tolerance.



8
9
10
# File 'lib/rekiq/contract.rb', line 8

def work_time_tolerance
  @work_time_tolerance
end

Class Method Details

.from_hash(hash) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/rekiq/contract.rb', line 19

def from_hash(hash)
  new 'schedule'            => Marshal.load(hash['s'].encode('ISO-8859-1')),
      'cancel_args'         => hash['ca'],
      'addon'               => hash['ao'],
      'schedule_post_work'  => hash['pw'],
      'work_time_shift'     => hash['ws'],
      'work_time_tolerance' => hash['wt'],
      'schedule_expired'    => hash['se']
end

Instance Method Details

#initial_work_time(from) ⇒ Object



52
53
54
55
# File 'lib/rekiq/contract.rb', line 52

def initial_work_time(from)
  from = (shift > 0 ? from - shift : from) - tolerance
  calculate_work_time(from)
end

#next_work_time(previous_work_time) ⇒ Object



57
58
59
60
# File 'lib/rekiq/contract.rb', line 57

def next_work_time(previous_work_time)
  from = previous_work_time - shift
  calculate_work_time(from)
end

#schedule_post_work?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/rekiq/contract.rb', line 62

def schedule_post_work?
  unless schedule_post_work.nil?
    schedule_post_work
  else
    Rekiq.configuration.schedule_post_work
  end
end

#to_hashObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rekiq/contract.rb', line 40

def to_hash
  {
    's'  => Marshal.dump(schedule).force_encoding('ISO-8859-1').encode('UTF-8'),
    'ca' => cancel_args,
    'ao' => addon,
    'pw' => schedule_post_work,
    'ws' => work_time_shift,
    'wt' => work_time_tolerance,
    'se' => schedule_expired
  }.delete_if { |k, v| v.nil? }
end