Class: Sus::Output::Status

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Status.



14
15
16
17
# File 'lib/sus/output/status.rb', line 14

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

Class Method Details

.register(output) ⇒ Object



9
10
11
12
# File 'lib/sus/output/status.rb', line 9

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

Instance Method Details

#indicatorObject



29
30
31
32
33
34
35
# File 'lib/sus/output/status.rb', line 29

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


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

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

#update(state, context = nil) ⇒ Object



24
25
26
27
# File 'lib/sus/output/status.rb', line 24

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