Module: MIDIEvents::Constant::Loader

Extended by:
Loader
Included in:
Loader
Defined in:
lib/midi-events/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



166
167
168
169
# File 'lib/midi-events/constant.rb', line 166

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



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/midi-events/constant.rb', line 174

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