Class: Karousel
- Inherits:
-
Object
- Object
- Karousel
- Defined in:
- lib/karousel.rb,
lib/karousel/job.rb,
lib/karousel/errors.rb,
lib/karousel/version.rb,
lib/karousel/client_job.rb
Overview
Implements karousel
Defined Under Namespace
Classes: ClientJob, Job, NotImplementedError
Constant Summary collapse
- STATUS =
{ init: 1, sent: 2, success: 3, failure: 4 }.freeze
- VERSION =
'0.10.0'
Instance Attribute Summary collapse
-
#seats ⇒ Object
readonly
Returns the value of attribute seats.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#time_interval ⇒ Object
readonly
Returns the value of attribute time_interval.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass, size = 10, time_interval = 0, data = nil) ⇒ Karousel
constructor
A new instance of Karousel.
- #populate ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(klass, size = 10, time_interval = 0, data = nil) ⇒ Karousel
Returns a new instance of Karousel.
17 18 19 20 21 22 23 |
# File 'lib/karousel.rb', line 17 def initialize(klass, size = 10, time_interval = 0, data = nil) @klass = klass @size = size @time_interval = time_interval @seats = [] @klass.load(data) if data end |
Instance Attribute Details
#seats ⇒ Object (readonly)
Returns the value of attribute seats.
10 11 12 |
# File 'lib/karousel.rb', line 10 def seats @seats end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
10 11 12 |
# File 'lib/karousel.rb', line 10 def size @size end |
#time_interval ⇒ Object (readonly)
Returns the value of attribute time_interval.
10 11 12 |
# File 'lib/karousel.rb', line 10 def time_interval @time_interval end |
Class Method Details
.version ⇒ Object
13 14 15 |
# File 'lib/karousel.rb', line 13 def self.version VERSION end |
Instance Method Details
#populate ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/karousel.rb', line 25 def populate new_seats = [] @klass.populate(@size - @seats.size).each do |inst| new_seats << Job.new(inst) end @seats = new_seats + @seats end |
#run(&block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/karousel.rb', line 33 def run(&block) populate until @seats.empty? send_request sleep(@time_interval) check_response yield if block populate end end |