Class: Charming::Events::TaskProgressEvent

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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

#currentObject (readonly)

Returns the value of attribute current

Returns:

  • (Object)

    the current value of current



8
9
10
# File 'lib/charming/events/task_progress_event.rb', line 8

def current
  @current
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



8
9
10
# File 'lib/charming/events/task_progress_event.rb', line 8

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



8
9
10
# File 'lib/charming/events/task_progress_event.rb', line 8

def name
  @name
end

#totalObject (readonly)

Returns the value of attribute total

Returns:

  • (Object)

    the current value of total



8
9
10
# File 'lib/charming/events/task_progress_event.rb', line 8

def total
  @total
end

Instance Method Details

#fractionObject

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