Class: OutputMode::Output Abstract
- Inherits:
-
Object
- Object
- OutputMode::Output
- Defined in:
- lib/output_mode/output.rb
Overview
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.
Direct Known Subclasses
OutputMode::Outputs::Delimited, OutputMode::Outputs::Tabulated, OutputMode::Outputs::Templated
Instance Attribute Summary collapse
-
#config ⇒ Hash
readonly
Additional key-values to modify the render.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#default ⇒ Object
readonly
Either a static default.
-
#no ⇒ Object
readonly
Either a static no value.
-
#procs ⇒ Array<#call>
readonly
The callable methods to generate output.
-
#yes ⇒ Object
readonly
Either a static yes value.
Instance Method Summary collapse
- #callables ⇒ Object
-
#generate(object) ⇒ Object
Returns the results of the
procsfor a particularobject. -
#initialize(*procs, default: nil, yes: 'true', no: 'false', context: {}, **config) ⇒ Output
constructor
Creates a new outputting instance from an array of procs.
-
#render(*data) ⇒ String
abstract
Renders the results of the procs into a string.
Constructor Details
#initialize(*procs, default: nil, yes: 'true', no: 'false', context: {}, **config) ⇒ Output
Creates a new outputting instance from an array of procs
56 57 58 59 60 61 62 63 |
# 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 |
Instance Attribute Details
#config ⇒ Hash (readonly)
Returns additional key-values to modify the render.
46 |
# File 'lib/output_mode/output.rb', line 46 attr_reader :procs, :config, :yes, :no, :default, :context |
#context ⇒ Object (readonly)
Returns the value of attribute context.
46 |
# File 'lib/output_mode/output.rb', line 46 attr_reader :procs, :config, :yes, :no, :default, :context |
#default ⇒ Object (readonly)
Returns either a static default.
46 |
# File 'lib/output_mode/output.rb', line 46 attr_reader :procs, :config, :yes, :no, :default, :context |
#no ⇒ Object (readonly)
Returns either a static no value.
46 |
# File 'lib/output_mode/output.rb', line 46 attr_reader :procs, :config, :yes, :no, :default, :context |
#procs ⇒ Array<#call> (readonly)
Returns the callable methods to generate output.
46 47 48 |
# File 'lib/output_mode/output.rb', line 46 def procs @procs end |
#yes ⇒ Object (readonly)
Returns either a static yes value.
46 |
# File 'lib/output_mode/output.rb', line 46 attr_reader :procs, :config, :yes, :no, :default, :context |
Instance Method Details
#callables ⇒ Object
65 66 67 |
# File 'lib/output_mode/output.rb', line 65 def callables procs end |
#generate(object) ⇒ Object
Returns the results of the procs for a particular object. It will apply the default, yes, and no values.
71 72 73 74 75 |
# File 'lib/output_mode/output.rb', line 71 def generate(object) procs.map do |callable| callable.generator(self).call(object) end end |
#render(*data) ⇒ String
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
87 88 89 |
# File 'lib/output_mode/output.rb', line 87 def render(*data) raise NotImplementedError end |