Class: Musa::Variatio::Variatio::B

Inherits:
Object
  • Object
show all
Defined in:
lib/musa-dsl/generative/variatio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter_name, options, affected_field_names, inner, blocks) ⇒ B

Returns a new instance of B.



205
206
207
208
209
210
211
212
# File 'lib/musa-dsl/generative/variatio.rb', line 205

def initialize(parameter_name, options, affected_field_names, inner, blocks)
  @parameter_name = parameter_name
  @options = options
  @affected_field_names = affected_field_names
  @inner = inner

  @procedures = blocks.collect { |proc| Musa::Extension::SmartProcBinder::SmartProcBinder.new proc }
end

Instance Attribute Details

#affected_field_namesObject (readonly)

Returns the value of attribute affected_field_names.



203
204
205
# File 'lib/musa-dsl/generative/variatio.rb', line 203

def affected_field_names
  @affected_field_names
end

#blocksObject (readonly)

Returns the value of attribute blocks.



203
204
205
# File 'lib/musa-dsl/generative/variatio.rb', line 203

def blocks
  @blocks
end

#innerObject (readonly)

Returns the value of attribute inner.



203
204
205
# File 'lib/musa-dsl/generative/variatio.rb', line 203

def inner
  @inner
end

#optionsObject (readonly)

Returns the value of attribute options.



203
204
205
# File 'lib/musa-dsl/generative/variatio.rb', line 203

def options
  @options
end

#parameter_nameObject (readonly)

Returns the value of attribute parameter_name.



203
204
205
# File 'lib/musa-dsl/generative/variatio.rb', line 203

def parameter_name
  @parameter_name
end

Instance Method Details

#inspectObject Also known as: to_s



239
240
241
# File 'lib/musa-dsl/generative/variatio.rb', line 239

def inspect
  "B name: #{@parameter_name}, options: #{@options}, affected_field_names: #{@affected_field_names}, blocks_size: #{@blocks.size}, inner: #{@inner}"
end

#run(parameters_with_depth, parent_parameters = nil) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/musa-dsl/generative/variatio.rb', line 214

def run(parameters_with_depth, parent_parameters = nil)
  parent_parameters ||= {}

  @options.each do |option|
    base = @parameter_name == :_maincontext ? parameters_with_depth : parameters_with_depth[@parameter_name][option]

    parameters = base.select { |k, _v| @affected_field_names.include? k }.merge(parent_parameters)
    parameters[@parameter_name] = option

    @procedures.each do |procedure_binder|
      procedure_binder.call **parameters
    end

    if @parameter_name == :_maincontext
      @inner.each do |inner|
        inner.run parameters_with_depth, parameters
      end
    else
      @inner.each do |inner|
        inner.run parameters_with_depth[@parameter_name][option], parameters
      end
    end
  end
end