Class: MIDIMessage::Constant::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-message/constant.rb

Overview

MIDI Constant container

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, constants) ⇒ Group

Returns a new instance of Group.

Parameters:

  • key (String)
  • constants (Hash)


53
54
55
56
# File 'lib/midi-message/constant.rb', line 53

def initialize(key, constants)
  @key = key
  @constants = constants.map { |k, v| Constant::Map.new(k, v) }
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



49
50
51
# File 'lib/midi-message/constant.rb', line 49

def constants
  @constants
end

#keyObject (readonly)

Returns the value of attribute key.



49
50
51
# File 'lib/midi-message/constant.rb', line 49

def key
  @key
end

Class Method Details

.allArray<ConstantGroup>

All constant groups

Returns:

  • (Array<ConstantGroup>)


76
77
78
79
# File 'lib/midi-message/constant.rb', line 76

def all
  ensure_initialized
  @groups
end

.find(key) ⇒ ConstantGroup Also known as: []

Find a constant group by its key

Parameters:

  • key (String, Symbol)

Returns:

  • (ConstantGroup)


84
85
86
87
# File 'lib/midi-message/constant.rb', line 84

def find(key)
  ensure_initialized
  @groups.find { |group| Name.match?(group.key, key) }
end

Instance Method Details

#find(name) ⇒ Constant::Map

Find a constant by its name

Parameters:

  • name (String, Symbol)

Returns:



61
62
63
# File 'lib/midi-message/constant.rb', line 61

def find(name)
  @constants.find { |const| Name.match?(const.key, name) }
end

#find_by_value(value) ⇒ Constant::Map

Find a constant by its value

Parameters:

  • value (Object)

Returns:



68
69
70
# File 'lib/midi-message/constant.rb', line 68

def find_by_value(value)
  @constants.find { |const| Name.match?(const.value, value) }
end