Class: Campo::Outputter
- Inherits:
-
Object
- Object
- Campo::Outputter
- Defined in:
- lib/campo/campo.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{n: 0, tab: 2}
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #after_output(&block) ⇒ Object
- #afters ⇒ Object
- #before_output(&block) ⇒ Object
- #befores ⇒ Object
- #check_for_plugins(type) ⇒ Object
-
#initialize(tab = nil, &block) ⇒ Outputter
constructor
A new instance of Outputter.
- #options ⇒ Object
- #run(fields, opts = {}) ⇒ Object
Constructor Details
#initialize(tab = nil, &block) ⇒ Outputter
Returns a new instance of Outputter.
395 396 397 398 |
# File 'lib/campo/campo.rb', line 395 def initialize( tab=nil, &block ) [:tab] = tab unless tab.nil? instance_eval( &block ) if block end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
400 401 402 |
# File 'lib/campo/campo.rb', line 400 def output @output end |
Instance Method Details
#after_output(&block) ⇒ Object
373 374 375 |
# File 'lib/campo/campo.rb', line 373 def after_output( &block ) afters << block end |
#afters ⇒ Object
383 384 385 |
# File 'lib/campo/campo.rb', line 383 def afters @afters ||= check_for_plugins :afters end |
#before_output(&block) ⇒ Object
368 369 370 |
# File 'lib/campo/campo.rb', line 368 def before_output( &block ) befores << block end |
#befores ⇒ Object
378 379 380 |
# File 'lib/campo/campo.rb', line 378 def befores @befores ||= check_for_plugins :befores end |
#check_for_plugins(type) ⇒ Object
388 389 390 391 392 |
# File 'lib/campo/campo.rb', line 388 def check_for_plugins( type ) Campo.plugins.reduce [] do |mem, (_,plugin)| mem + plugin.send(:"#{type}" ) end end |
#options ⇒ Object
405 406 407 |
# File 'lib/campo/campo.rb', line 405 def @options ||= DEFAULT_OPTIONS end |
#run(fields, opts = {}) ⇒ Object
410 411 412 413 414 415 416 417 418 419 |
# File 'lib/campo/campo.rb', line 410 def run( fields, opts={} ) opts = .merge opts tab = opts.delete(:tab) || @tab output = "" befores.each{|f| instance_exec( fields, , &f ) } output = Base.output( fields, output, [:n], tab ) output = afters.reduce(output){|mem,obj| instance_exec mem, opts, &obj } output end |