Module: MIDIEvents::Constant::Loader Private

Extended by:
Loader
Included in:
Loader
Defined in:
lib/midi-events/constant.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal system for loading constants into message objects

Handles the automatic population of message metadata (names, verbose names) based on constant definitions in midi.yml.

Defined Under Namespace

Modules: DSL

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_index(message) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the property index for a constant in a message

Parameters:

Returns:

  • (Integer)

    The index of the constant property



277
278
279
280
# File 'lib/midi-events/constant.rb', line 277

def get_index(message)
  key = message.class.constant_property
  message.class.properties.index(key) || 0
end

.get_info(message) ⇒ Hash?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Populate message metadata using constant information from midi.yml

Looks up the constant for a message and returns metadata including the constant object, name, and verbose name.

Parameters:

Returns:

  • (Hash, nil)

    Hash with :const, :name, :verbose_name keys, or nil



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/midi-events/constant.rb', line 289

def get_info(message)
  const_group_name = message.class.display_name
  group_name_alias = message.class.constant_name
  property = message.class.constant_property
  value = message.send(property) unless property.nil?
  value ||= message.status[1] # default property to use for constants
  group = Constant::Group[group_name_alias] || Constant::Group[const_group_name]
  unless group.nil?
    unless (const = group.find_by_value(value)).nil?
      {
        const: const,
        name: const.key,
        verbose_name: "#{message.class.display_name}: #{const.key}"
      }
    end
  end
end

Instance Method Details

#get_index(message) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the property index for a constant in a message

Parameters:

Returns:

  • (Integer)

    The index of the constant property



277
278
279
280
# File 'lib/midi-events/constant.rb', line 277

def get_index(message)
  key = message.class.constant_property
  message.class.properties.index(key) || 0
end

#get_info(message) ⇒ Hash?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Populate message metadata using constant information from midi.yml

Looks up the constant for a message and returns metadata including the constant object, name, and verbose name.

Parameters:

Returns:

  • (Hash, nil)

    Hash with :const, :name, :verbose_name keys, or nil



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/midi-events/constant.rb', line 289

def get_info(message)
  const_group_name = message.class.display_name
  group_name_alias = message.class.constant_name
  property = message.class.constant_property
  value = message.send(property) unless property.nil?
  value ||= message.status[1] # default property to use for constants
  group = Constant::Group[group_name_alias] || Constant::Group[const_group_name]
  unless group.nil?
    unless (const = group.find_by_value(value)).nil?
      {
        const: const,
        name: const.key,
        verbose_name: "#{message.class.display_name}: #{const.key}"
      }
    end
  end
end