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
- #id ⇒ 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.
11 12 13 14 |
# File 'lib/barr/manager.rb', line 11 def initialize @count = 0 @blocks = [] end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
9 10 11 |
# File 'lib/barr/manager.rb', line 9 def blocks @blocks end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
9 10 11 |
# File 'lib/barr/manager.rb', line 9 def count @count end |
Instance Method Details
#add(block) ⇒ Object
16 17 18 19 |
# File 'lib/barr/manager.rb', line 16 def add(block) block.manager = self @blocks << block end |
#add_block(block) ⇒ Object
79 |
# File 'lib/barr/manager.rb', line 79 def add_block(block); add(block); end |
#destroy ⇒ Object
78 |
# File 'lib/barr/manager.rb', line 78 def destroy; destroy!; end |
#destroy! ⇒ Object
21 22 23 |
# File 'lib/barr/manager.rb', line 21 def destroy! @blocks.each(&:destroy!) end |
#draw ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/barr/manager.rb', line 25 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 |
#id ⇒ Object
68 69 70 |
# File 'lib/barr/manager.rb', line 68 def id @id ||= SecureRandom.uuid end |
#run ⇒ Object
77 |
# File 'lib/barr/manager.rb', line 77 def run; run!; end |
#run! ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/barr/manager.rb', line 46 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
76 |
# File 'lib/barr/manager.rb', line 76 def update; update!; end |
#update! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/barr/manager.rb', line 54 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 |