Class: Brandish::Processor::Inline

Inherits:
Base
  • Object
show all
Defined in:
lib/brandish/processor/inline.rb

Overview

An inline-defined processor. This allows processors to be defined easily within a block. This is mostly used for configuration.

Examples:

class RFC < Brandish::Processor::Inline
  command! :rfc
  pairs :number

  perform do
    number = @pairs.fetch("number")
    "<a href='https://www.ietf.org/rfc/rfc#{number}.txt'>RFC #{number}</a>"
  end
end

Instance Attribute Summary

Attributes inherited from Base

#context

Class Method Summary collapse

Methods inherited from Base

#accept, #call, #initialize, #postprocess, #process_block, #process_command, #process_root, #process_text, register, #setup

Constructor Details

This class inherits a constructor from Brandish::Processor::Base

Class Method Details

.block!(*names) ⇒ void

This method returns an undefined value.

Sets this processor as a block processor. This include Block, and passes the given names to NameFilter::ClassMethods#name.



34
35
36
37
# File 'lib/brandish/processor/inline.rb', line 34

def self.block!(*names)
  include Block
  name(*names)
end

.command!(*names) ⇒ void

This method returns an undefined value.

Sets this processor as a command processor. This includes Command, and passes the given names to NameFilter::ClassMethods#name.



25
26
27
28
# File 'lib/brandish/processor/inline.rb', line 25

def self.command!(*names)
  include Command
  name(*names)
end

.perform(&block) ⇒ void

This method returns an undefined value.

Defines the #perform method with the given block. This is only effective if one of Command or Block is included. This takes the block passed to it and uses that to define the #perform method.



44
45
46
# File 'lib/brandish/processor/inline.rb', line 44

def self.perform(&block)
  define_method(:perform, &block)
end