Class: Molder::Template
- Inherits:
-
Object
- Object
- Molder::Template
- Defined in:
- lib/molder/template.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#command ⇒ Object
Returns the value of attribute command.
-
#config ⇒ Object
Returns the value of attribute config.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #each_command ⇒ Object
-
#initialize(config:, name:, indexes:, attributes: {}, command:) ⇒ Template
constructor
A new instance of Template.
Constructor Details
#initialize(config:, name:, indexes:, attributes: {}, command:) ⇒ Template
Returns a new instance of Template.
6 7 8 9 10 11 12 |
# File 'lib/molder/template.rb', line 6 def initialize(config:, name:, indexes:, attributes: {}, command:) self.config = config self.name = name self.indexes = indexes self.command = command self.attributes = self.class.normalize(attributes) end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/molder/template.rb', line 4 def attributes @attributes end |
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/molder/template.rb', line 4 def command @command end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/molder/template.rb', line 4 def config @config end |
#indexes ⇒ Object
Returns the value of attribute indexes.
4 5 6 |
# File 'lib/molder/template.rb', line 4 def indexes @indexes end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/molder/template.rb', line 4 def name @name end |
Class Method Details
.normalize(attrs) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/molder/template.rb', line 24 def self.normalize(attrs) override = {} attrs.each_pair do |key, value| if value.is_a?(Hash) && value.values.compact.empty? override[key] = value.keys.to_a.join(',') end end attrs.merge!(override) end |
Instance Method Details
#each_command ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/molder/template.rb', line 14 def each_command indexes.map do |i| self.attributes[:number] = i self.attributes[:formatted_number] = sprintf(config.global.index_format, i) ::Molder::Renderer.new(command.args).render(attributes.dup).tap do |cmd| yield(cmd) if block_given? end end end |