Class: OutputMode::Outputs::Templated::Entry
- Inherits:
-
Struct
- Object
- Struct
- OutputMode::Outputs::Templated::Entry
- Includes:
- Enumerable
- Defined in:
- lib/output_mode/outputs/templated.rb
Instance Attribute Summary collapse
-
#colorize ⇒ Object
Returns the value of attribute colorize.
-
#model ⇒ Object
Returns the value of attribute model.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #each(section = nil) {|value, field:, padding:, **config| ... } ⇒ Object
-
#pastel ⇒ Object
Library for colorizing the output.
-
#render(erb) ⇒ String
Renders an ERB object within the entry’s context.
Instance Attribute Details
#colorize ⇒ Object
Returns the value of attribute colorize
34 35 36 |
# File 'lib/output_mode/outputs/templated.rb', line 34 def colorize @colorize end |
#model ⇒ Object
Returns the value of attribute model
34 35 36 |
# File 'lib/output_mode/outputs/templated.rb', line 34 def model @model end |
#output ⇒ Object
Returns the value of attribute output
34 35 36 |
# File 'lib/output_mode/outputs/templated.rb', line 34 def output @output end |
Instance Method Details
#each(section = nil) {|value, field:, padding:, **config| ... } ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/output_mode/outputs/templated.rb', line 41 def each(section = nil, &block) # Select the callable objects callables = if section == nil output.callables elsif section == :default output.callables.config_select(:section, :default, nil) else output.callables.config_select(:section, section) end # Yield each selected attribute objs = callables.pad_each(model, **output.context).map do |callable, padding:, field:| value = callable.generator(output).call(model) [value, { field: field, padding: padding }] end # Runs the provided block objs.each do |model, opts| block.call(model, **opts) end end |
#pastel ⇒ Object
Library for colorizing the output. It is automatically disabled when the colorize
flag is false
74 75 76 |
# File 'lib/output_mode/outputs/templated.rb', line 74 def pastel @pastel ||= Pastel.new(enabled: colorize) end |
#render(erb) ⇒ String
Renders an ERB object within the entry’s context. This provides access to the output
, model
, and enumerable
methods
68 69 70 |
# File 'lib/output_mode/outputs/templated.rb', line 68 def render(erb) erb.result(binding) end |