Class: Sus::Output::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/output/status.rb

Overview

Represents a status indicator for test execution.

Constant Summary collapse

INDICATORS =

Status indicators for different states.

{
	busy: ["", "", "", ""],
	free: [""]
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state = :free, context = nil) ⇒ Status

Initialize a new Status indicator.



20
21
22
23
# File 'lib/sus/output/status.rb', line 20

def initialize(state = :free, context = nil)
	@state = state
	@context = context
end

Class Method Details

.register(output) ⇒ Object

Register status styling with an output handler.



12
13
14
15
# File 'lib/sus/output/status.rb', line 12

def self.register(output)
	output[:free] ||= output.style(:green)
	output[:busy] ||= output.style(:blue)
end

Instance Method Details

#indicatorObject



40
41
42
43
44
45
46
# File 'lib/sus/output/status.rb', line 40

def indicator
	if indicators = INDICATORS[@state]
		return indicators[(Time.now.to_f * 10) % indicators.size]
	end
	
	return " "
end

Print the status to the output.



50
51
52
53
54
55
56
57
58
# File 'lib/sus/output/status.rb', line 50

def print(output)
	output.write(
		@state, self.indicator, " "
	)
	
	output.write(@context)
	
	output.puts
end

#update(state, context = nil) ⇒ Object

Update the status.



34
35
36
37
# File 'lib/sus/output/status.rb', line 34

def update(state, context = nil)
	@state = state
	@context = context
end