Module: MIDIEvents::Constant::Loader::DSL

Defined in:
lib/midi-events/constant.rb

Overview

DSL type class methods for loading constants into messages

Instance Method Summary collapse

Instance Method Details

#constant_mapHash

Returns:

  • (Hash)


211
212
213
# File 'lib/midi-events/constant.rb', line 211

def constant_map
  const_get('CONSTANT') if const_defined?('CONSTANT')
end

#constant_nameString

Returns:

  • (String)


216
217
218
# File 'lib/midi-events/constant.rb', line 216

def constant_name
  constant_map&.keys&.first
end

#constant_propertySymbol

Returns:

  • (Symbol)


221
222
223
# File 'lib/midi-events/constant.rb', line 221

def constant_property
  constant_map[constant_name] unless constant_map.nil?
end

#display_nameString

Returns:

  • (String)


206
207
208
# File 'lib/midi-events/constant.rb', line 206

def display_name
  const_get('DISPLAY_NAME') if const_defined?('DISPLAY_NAME')
end

#find(const_name) ⇒ MIDIEvents::MessageBuilder Also known as: []

This returns a MessageBuilder for the class, preloaded with the selected const

Parameters:

  • const_name (String, Symbol)

    The constant key to use to build the message

Returns:

  • (MIDIEvents::MessageBuilder)

    A MessageBuilder object for the passed in constant



234
235
236
237
# File 'lib/midi-events/constant.rb', line 234

def find(const_name)
  const = get_constant(const_name.to_s)
  MessageBuilder.new(self, const) unless const.nil?
end

#get_constant(name) ⇒ String

Find a constant value in this class’s group for the passed in key

Parameters:

  • name (String)

    The constant key

Returns:

  • (String)

    The constant value



197
198
199
200
201
202
203
# File 'lib/midi-events/constant.rb', line 197

def get_constant(name)
  key = constant_name || display_name
  return if key.nil?

  group = Group[key]
  group.find(name)
end

#type_for_statusFixnum

Get the status nibble for this particular message type

Returns:

  • (Fixnum)

    The status nibble



227
228
229
# File 'lib/midi-events/constant.rb', line 227

def type_for_status
  Constant::Status[display_name]
end