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

#[](const_name) ⇒ MIDIMessage::MessageBuilder

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



203
204
205
206
# File 'lib/midi-message/constant.rb', line 203

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

#constant_mapHash

Returns:

  • (Hash)


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

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

#constant_nameString

Returns:

  • (String)


185
186
187
# File 'lib/midi-message/constant.rb', line 185

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

#constant_propertySymbol

Returns:

  • (Symbol)


190
191
192
# File 'lib/midi-message/constant.rb', line 190

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

#display_nameString

Returns:

  • (String)


175
176
177
# File 'lib/midi-message/constant.rb', line 175

def display_name
  const_get("DISPLAY_NAME") if const_defined?("DISPLAY_NAME")
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



166
167
168
169
170
171
172
# File 'lib/midi-message/constant.rb', line 166

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



196
197
198
# File 'lib/midi-message/constant.rb', line 196

def type_for_status
  Constant::Status[display_name]
end