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.
403 404 405 406 |
# File 'lib/campo/campo.rb', line 403 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.
408 409 410 |
# File 'lib/campo/campo.rb', line 408 def output @output end |
Instance Method Details
#after_output(&block) ⇒ Object
381 382 383 |
# File 'lib/campo/campo.rb', line 381 def after_output( &block ) afters << block end |
#afters ⇒ Object
391 392 393 |
# File 'lib/campo/campo.rb', line 391 def afters @afters ||= check_for_plugins :afters end |
#before_output(&block) ⇒ Object
376 377 378 |
# File 'lib/campo/campo.rb', line 376 def before_output( &block ) befores << block end |
#befores ⇒ Object
386 387 388 |
# File 'lib/campo/campo.rb', line 386 def befores @befores ||= check_for_plugins :befores end |
#check_for_plugins(type) ⇒ Object
396 397 398 399 400 |
# File 'lib/campo/campo.rb', line 396 def check_for_plugins( type ) Campo.plugins.reduce [] do |mem, (_,plugin)| mem + plugin.send(:"#{type}" ) end end |
#options ⇒ Object
413 414 415 |
# File 'lib/campo/campo.rb', line 413 def @options ||= DEFAULT_OPTIONS end |
#run(fields, opts = {}) ⇒ Object
418 419 420 421 422 423 424 425 426 427 |
# File 'lib/campo/campo.rb', line 418 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 |