Module: MIDIMessage::Constant::Loader

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

Overview

Loading constants from the spec file into messages

Defined Under Namespace

Modules: DSL

Instance Method Summary collapse

Instance Method Details

#get_index(message) ⇒ Fixnum

Get the index of the constant from the given message’s type

Parameters:

Returns:

  • (Fixnum)


179
180
181
182
# File 'lib/midi-message/constant.rb', line 179

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

#get_info(message) ⇒ Hash?

Used to populate message metadata with information gathered from midi.yml

Parameters:

Returns:

  • (Hash, nil)


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/midi-message/constant.rb', line 187

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