Class: ProxyRb::Announcer
- Inherits:
-
Object
- Object
- ProxyRb::Announcer
- Defined in:
- lib/proxy_rb/announcer.rb
Overview
Announcer
Defined Under Namespace
Classes: KernelPutsAnnouncer, PutsAnnouncer
Instance Method Summary collapse
-
#activate(*chns) ⇒ Object
Activate a channel.
-
#activated?(channel) ⇒ Boolean
Check if channel is activated.
-
#announce(channel, *args) { ... } ⇒ Object
Announce information to channel.
-
#initialize(*args) ⇒ Announcer
constructor
A new instance of Announcer.
-
#mode=(m) ⇒ Object
Change mode of announcer.
-
#reset ⇒ Object
Reset announcer.
Constructor Details
#initialize(*args) ⇒ Announcer
Returns a new instance of Announcer.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/proxy_rb/announcer.rb', line 58 def initialize(*args) @announcers = [] @announcers << PutsAnnouncer.new @announcers << KernelPutsAnnouncer.new @colorizer = ProxyRb::Colorizer.new @announcer = @announcers.first @channels = {} @output_formats = {} @options = args[1] || {} after_init end |
Instance Method Details
#activate(*chns) ⇒ Object
Activate a channel
124 125 126 127 128 |
# File 'lib/proxy_rb/announcer.rb', line 124 def activate(*chns) chns.flatten.each { |c| channels[c.to_sym] = true } self end |
#activated?(channel) ⇒ Boolean
Check if channel is activated
116 117 118 |
# File 'lib/proxy_rb/announcer.rb', line 116 def activated?(channel) channels[channel.to_sym] == true end |
#announce(channel, *args) { ... } ⇒ Object
Announce information to channel
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/proxy_rb/announcer.rb', line 141 def announce(channel, *args, &_block) channel = channel.to_sym the_output_format = if output_formats.key? channel output_formats[channel] else proc { |v| format('%s', v) } end return unless activated?(channel) = if block_given? the_output_format.call(yield) else the_output_format.call(*args) end += "\n" = colorizer.cyan() announcer.announce() nil end |
#mode=(m) ⇒ Object
Change mode of announcer
106 107 108 109 110 |
# File 'lib/proxy_rb/announcer.rb', line 106 def mode=(m) @announcer = @announcers.find { |_a| f.mode? m.to_sym } self end |
#reset ⇒ Object
Reset announcer
98 99 100 |
# File 'lib/proxy_rb/announcer.rb', line 98 def reset @announcer = @announcers.first end |