Class: Potassium::TextSpinner
- Inherits:
-
Object
- Object
- Potassium::TextSpinner
- Defined in:
- lib/potassium/text_spinner.rb
Overview
TODO: I don’t know if this is a concern of this gem. Maybe we should move this later
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
{ wait_condition: -> {}, base_message: "", interval: 0.4, message_continuations: ["", ".", "..", "..."] }
Instance Attribute Summary collapse
-
#base_message ⇒ Object
Returns the value of attribute base_message.
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#message_continuations ⇒ Object
Returns the value of attribute message_continuations.
-
#started ⇒ Object
Returns the value of attribute started.
-
#wait_condition ⇒ Object
Returns the value of attribute wait_condition.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ TextSpinner
constructor
A new instance of TextSpinner.
- #start ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ TextSpinner
Returns a new instance of TextSpinner.
14 15 16 17 18 19 20 |
# File 'lib/potassium/text_spinner.rb', line 14 def initialize(attributes = {}) DEFAULT_ATTRIBUTES.merge(attributes).each do |key, value| public_send("#{key}=", value) end self.started = false self.counter = 0 end |
Instance Attribute Details
#base_message ⇒ Object
Returns the value of attribute base_message.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def @base_message end |
#counter ⇒ Object
Returns the value of attribute counter.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def counter @counter end |
#interval ⇒ Object
Returns the value of attribute interval.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def interval @interval end |
#message_continuations ⇒ Object
Returns the value of attribute message_continuations.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def @message_continuations end |
#started ⇒ Object
Returns the value of attribute started.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def started @started end |
#wait_condition ⇒ Object
Returns the value of attribute wait_condition.
4 5 6 |
# File 'lib/potassium/text_spinner.rb', line 4 def wait_condition @wait_condition end |
Instance Method Details
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/potassium/text_spinner.rb', line 22 def start fail if started self.started = true Thread.new do loop do break if wait_condition.call(counter) sleep interval self.counter += 1 end self.started = false end end |