Module: MIDIEvents::Constant::Name Private

Extended by:
Name
Included in:
Name
Defined in:
lib/midi-events/constant.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Name manipulation utilities for constant lookups

Provides methods to normalize and compare constant names in a case-insensitive manner, supporting both "Control Change" and "control_change" formats.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match?(key, other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if two names match (case-insensitive, supports underscored or spaced)

Examples:

MIDIEvents::Constant::Name.match?("Control Change", "control_change")
# => true

Parameters:

  • key (Symbol, String)

    First name to compare

  • other (Symbol, String)

    Second name to compare

Returns:

  • (Boolean)

    True if names match



73
74
75
76
# File 'lib/midi-events/constant.rb', line 73

def match?(key, other)
  match_key = key.to_s.downcase
  [match_key, Name.underscore(match_key)].include?(other.to_s.downcase)
end

.underscore(string) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert a name to underscore format

Examples:

MIDIEvents::Constant::Name.underscore("Control Change")
# => "control_change"

Parameters:

  • string (Symbol, String)

    The name to convert

Returns:

  • (String)

    The underscored version



60
61
62
# File 'lib/midi-events/constant.rb', line 60

def underscore(string)
  string.to_s.downcase.gsub(/(\ )+/, '_')
end

Instance Method Details

#match?(key, other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if two names match (case-insensitive, supports underscored or spaced)

Examples:

MIDIEvents::Constant::Name.match?("Control Change", "control_change")
# => true

Parameters:

  • key (Symbol, String)

    First name to compare

  • other (Symbol, String)

    Second name to compare

Returns:

  • (Boolean)

    True if names match



73
74
75
76
# File 'lib/midi-events/constant.rb', line 73

def match?(key, other)
  match_key = key.to_s.downcase
  [match_key, Name.underscore(match_key)].include?(other.to_s.downcase)
end

#underscore(string) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert a name to underscore format

Examples:

MIDIEvents::Constant::Name.underscore("Control Change")
# => "control_change"

Parameters:

  • string (Symbol, String)

    The name to convert

Returns:

  • (String)

    The underscored version



60
61
62
# File 'lib/midi-events/constant.rb', line 60

def underscore(string)
  string.to_s.downcase.gsub(/(\ )+/, '_')
end