Class: Ecoportal::API::V1::Job::Status
- Inherits:
-
Object
- Object
- Ecoportal::API::V1::Job::Status
- Defined in:
- lib/ecoportal/api/v1/job/status.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #complete?(total = nil) ⇒ Boolean
- #errored? ⇒ Boolean
-
#initialize(id, complete, errored, progress) ⇒ Status
constructor
A new instance of Status.
- #pending(total) ⇒ Object
- #progress_increase(prev = 0) ⇒ Object
- #progressing?(prev) ⇒ Boolean
- #started? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(id, complete, errored, progress) ⇒ Status
Returns a new instance of Status.
8 9 10 11 12 13 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 8 def initialize(id, complete, errored, progress) @id = id @complete = complete @errored = errored @progress = progress || 0 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 6 def id @id end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
6 7 8 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 6 def progress @progress end |
Instance Method Details
#complete?(total = nil) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 23 def complete?(total = nil) return @complete if total.nil? progress >= total end |
#errored? ⇒ Boolean
42 43 44 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 42 def errored? @errored end |
#pending(total) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 29 def pending(total) return 1 unless total return 0 if total <= progress total - progress end |
#progress_increase(prev = 0) ⇒ Object
36 37 38 39 40 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 36 def progress_increase(prev = 0) prev = prev.progress if prev.is_a?(self.class) prev ||= 0 progress - prev end |
#progressing?(prev) ⇒ Boolean
19 20 21 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 19 def progressing?(prev) progress_increase(prev).positive? end |
#started? ⇒ Boolean
15 16 17 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 15 def started? progress.positive? end |
#to_s ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ecoportal/api/v1/job/status.rb', line 46 def to_s msg = complete? ? 'Completed' : 'In progress' msg = 'Errored' if errored? msg << " with #{progress} done." msg end |