class OutputMode::Output
@abstract Defines the public interface to all subclasses
Base outputting class that wraps an array of procs or other callable object. Each implementation must override the {#render} method so it returns an array.
Attributes
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
@!attribute [r] procs
@return [Array<#call>] the callable methods to generate output
@!attribute [r] config
@return [Hash] additional key-values to modify the render
@!attribute [r] default
@return either a static default
@!attribute [r] yes
@return either a static yes value
@!attribute [r] no
@return either a static no value
@!attribute [r] context
@return a hash of keys to be provided to the callables
Public Class Methods
Creates a new outputting instance from an array of procs
@param *procs [Array<#call>] an array of procs (or callable objects) @param default: [String] replaces blanks with a static string @param yes: [String] replaces true
with a static string @param no: [String] replaces false
with a static string @param context: [Hash] of keys to be provided to the callables @param **config [Hash] a hash of additional keys to be stored
# File lib/output_mode/output.rb, line 56 def initialize(*procs, default: nil, yes: 'true', no: 'false', context: {}, **config) @procs = Callables.new(procs) @config = config @yes = yes @no = no @default = default @context = context end
Public Instance Methods
# File lib/output_mode/output.rb, line 65 def callables procs end
Returns the results of the procs
for a particular object
. It will apply the default
, yes
, and no
values.
# File lib/output_mode/output.rb, line 71 def generate(object) procs.map do |callable| callable.generator(self).call(object) end end
@abstract It should be implemented by the subclass using the generate
method Renders the results of the procs into a string. Each data objects should be passed individual to each proc to generate the final output.
The method must be overridden on all inherited classes
@param *data [Array] a set of data to be rendered into the output @return [String] the output string @see generate
# File lib/output_mode/output.rb, line 87 def render(*data) raise NotImplementedError end