Class: Barr::Manager
- Inherits:
-
Object
- Object
- Barr::Manager
- Defined in:
- lib/barr/manager.rb
Constant Summary collapse
- ERROR_ICON =
"%{F#FF0000}\uf071%{F-}"
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #add(block) ⇒ Object
- #add_block(block) ⇒ Object
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #run ⇒ Object
- #run! ⇒ Object
-
#update ⇒ Object
compatibility methods.
- #update! ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
10 11 12 13 |
# File 'lib/barr/manager.rb', line 10 def initialize @count = 0 @blocks = [] end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
8 9 10 |
# File 'lib/barr/manager.rb', line 8 def blocks @blocks end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
8 9 10 |
# File 'lib/barr/manager.rb', line 8 def count @count end |
Instance Method Details
#add(block) ⇒ Object
15 16 17 |
# File 'lib/barr/manager.rb', line 15 def add(block) @blocks << block end |
#add_block(block) ⇒ Object
73 |
# File 'lib/barr/manager.rb', line 73 def add_block(block); add(block); end |
#destroy ⇒ Object
72 |
# File 'lib/barr/manager.rb', line 72 def destroy; destroy!; end |
#destroy! ⇒ Object
19 20 21 |
# File 'lib/barr/manager.rb', line 19 def destroy! @blocks.each(&:destroy!) end |
#draw ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/barr/manager.rb', line 23 def draw outputs = { l: [], c: [], r: [] } @blocks.each do |block| outputs[block.align] << block.draw end left_blocks = outputs[:l].join '' centre_blocks = outputs[:c].join '' right_blocks = outputs[:r].join '' = '' << "%{l}#{left_blocks} " if left_blocks.length > 0 << "%{c} #{centre_blocks} " if centre_blocks.length > 0 << "%{r} #{right_blocks}" if right_blocks.length > 0 .gsub! "\n", '' system('echo', '-e', .encode('UTF-8')) end |
#run ⇒ Object
71 |
# File 'lib/barr/manager.rb', line 71 def run; run!; end |
#run! ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/barr/manager.rb', line 44 def run! while true self.update! self.draw sleep 1 end end |
#update ⇒ Object
compatibility methods. alias_method would work here, but for consistency with Block I’ll define them this way
70 |
# File 'lib/barr/manager.rb', line 70 def update; update!; end |
#update! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/barr/manager.rb', line 52 def update! @blocks.each do |block| begin block.update! if @count == 0 || (@count % block.interval == 0) rescue StandardError => e STDERR.puts e. block << ERROR_ICON unless block.output.include?(ERROR_ICON) next end end @count += 1 end |