Module: MIDIMessage::Constant::Loader::DSL

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

Overview

DSL type class methods for loading constants into messages

Instance Method Summary collapse

Instance Method Details

#constant_mapHash

Returns:

  • (Hash)

225
226
227
# File 'lib/midi-message/constant.rb', line 225

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

#constant_nameString

Returns:

  • (String)

230
231
232
# File 'lib/midi-message/constant.rb', line 230

def constant_name
  constant_map.keys.first unless constant_map.nil?
end

#constant_propertySymbol

Returns:

  • (Symbol)

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

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

#display_nameString

Returns:

  • (String)

220
221
222
# File 'lib/midi-message/constant.rb', line 220

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

#find(const_name) ⇒ MIDIMessage::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:

  • (MIDIMessage::MessageBuilder)

    A MessageBuilder object for the passed in constant


248
249
250
251
# File 'lib/midi-message/constant.rb', line 248

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


211
212
213
214
215
216
217
# File 'lib/midi-message/constant.rb', line 211

def get_constant(name)
  key = constant_name || display_name
  unless key.nil?
    group = Group[key]
    group.find(name)
  end
end

#type_for_statusFixnum

Get the status nibble for this particular message type

Returns:

  • (Fixnum)

    The status nibble


241
242
243
# File 'lib/midi-message/constant.rb', line 241

def type_for_status
  Constant::Status[display_name]
end