Class: Charming::Events::TaskProgressEvent
- Inherits:
-
Data
- Object
- Data
- Charming::Events::TaskProgressEvent
- Defined in:
- lib/charming/events/task_progress_event.rb
Overview
TaskProgressEvent reports incremental progress from a running background task. name matches the task name, current/total describe completion (total may be nil for indeterminate work), and message is an optional human-readable status.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#fraction ⇒ Object
Completion as a 0.0..1.0 fraction, or nil when the total is unknown.
-
#initialize(name:, current:, total: nil, message: nil) ⇒ TaskProgressEvent
constructor
A new instance of TaskProgressEvent.
Constructor Details
#initialize(name:, current:, total: nil, message: nil) ⇒ TaskProgressEvent
Returns a new instance of TaskProgressEvent.
9 10 11 |
# File 'lib/charming/events/task_progress_event.rb', line 9 def initialize(name:, current:, total: nil, message: nil) super end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current
8 9 10 |
# File 'lib/charming/events/task_progress_event.rb', line 8 def current @current end |
#message ⇒ Object (readonly)
Returns the value of attribute message
8 9 10 |
# File 'lib/charming/events/task_progress_event.rb', line 8 def @message end |
#name ⇒ Object (readonly)
Returns the value of attribute name
8 9 10 |
# File 'lib/charming/events/task_progress_event.rb', line 8 def name @name end |
#total ⇒ Object (readonly)
Returns the value of attribute total
8 9 10 |
# File 'lib/charming/events/task_progress_event.rb', line 8 def total @total end |
Instance Method Details
#fraction ⇒ Object
Completion as a 0.0..1.0 fraction, or nil when the total is unknown.
14 15 16 17 18 |
# File 'lib/charming/events/task_progress_event.rb', line 14 def fraction return nil unless total&.positive? (current.to_f / total).clamp(0.0, 1.0) end |