Class: Rekiq::Contract
- Inherits:
-
Object
- Object
- Rekiq::Contract
- Includes:
- Validator
- Defined in:
- lib/rekiq/contract.rb
Constant Summary
Constants included from Validator
Instance Attribute Summary collapse
-
#addon ⇒ Object
Returns the value of attribute addon.
-
#cancel_args ⇒ Object
Returns the value of attribute cancel_args.
-
#schedule ⇒ Object
Returns the value of attribute schedule.
-
#schedule_expired ⇒ Object
Returns the value of attribute schedule_expired.
-
#schedule_post_work ⇒ Object
Returns the value of attribute schedule_post_work.
-
#work_time_shift ⇒ Object
Returns the value of attribute work_time_shift.
-
#work_time_tolerance ⇒ Object
Returns the value of attribute work_time_tolerance.
Class Method Summary collapse
Instance Method Summary collapse
- #initial_work_time(from) ⇒ Object
-
#initialize(attributes = {}) ⇒ Contract
constructor
A new instance of Contract.
- #next_work_time(previous_work_time) ⇒ Object
- #schedule_post_work? ⇒ Boolean
- #to_hash ⇒ Object
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
#addon ⇒ Object
Returns the value of attribute addon.
8 9 10 |
# File 'lib/rekiq/contract.rb', line 8 def addon @addon end |
#cancel_args ⇒ Object
Returns the value of attribute cancel_args.
8 9 10 |
# File 'lib/rekiq/contract.rb', line 8 def cancel_args @cancel_args end |
#schedule ⇒ Object
Returns the value of attribute schedule.
8 9 10 |
# File 'lib/rekiq/contract.rb', line 8 def schedule @schedule end |
#schedule_expired ⇒ Object
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_work ⇒ Object
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_shift ⇒ Object
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_tolerance ⇒ Object
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
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_hash ⇒ Object
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 |