Class: MIDIEvents::Constant::Group
- Inherits:
-
Object
- Object
- MIDIEvents::Constant::Group
- Defined in:
- lib/midi-events/constant.rb
Overview
Container for a group of related MIDI constants
Groups organize constants by category (e.g., "Note", "Control Change", "Status"). Each group contains multiple Map objects that pair constant names with their values.
Instance Attribute Summary collapse
-
#constants ⇒ Array<MIDIEvents::Constant::Map>
readonly
The constants in this group.
-
#key ⇒ String
readonly
The group's key/name.
Class Method Summary collapse
-
.all ⇒ Array<ConstantGroup>
All constant groups.
-
.find(key) ⇒ ConstantGroup
(also: [])
Find a constant group by its key.
Instance Method Summary collapse
-
#find(name) ⇒ MIDIEvents::Constant::Map?
Find a constant in this group by its name.
-
#find_by_value(value) ⇒ MIDIEvents::Constant::Map?
Find a constant in this group by its value (reverse lookup).
-
#initialize(key, constants) ⇒ Group
constructor
Create a new constant group.
Constructor Details
#initialize(key, constants) ⇒ Group
Create a new constant group
100 101 102 103 |
# File 'lib/midi-events/constant.rb', line 100 def initialize(key, constants) @key = key @constants = constants.map { |k, v| Constant::Map.new(k, v) } end |
Instance Attribute Details
#constants ⇒ Array<MIDIEvents::Constant::Map> (readonly)
Returns The constants in this group.
91 92 93 |
# File 'lib/midi-events/constant.rb', line 91 def constants @constants end |
#key ⇒ String (readonly)
Returns The group's key/name.
94 95 96 |
# File 'lib/midi-events/constant.rb', line 94 def key @key end |
Class Method Details
.all ⇒ Array<ConstantGroup>
All constant groups
132 133 134 135 |
# File 'lib/midi-events/constant.rb', line 132 def all ensure_initialized @groups end |
.find(key) ⇒ ConstantGroup Also known as: []
Find a constant group by its key
140 141 142 143 |
# File 'lib/midi-events/constant.rb', line 140 def find(key) ensure_initialized @groups.find { |group| Name.match?(group.key, key) } end |
Instance Method Details
#find(name) ⇒ MIDIEvents::Constant::Map?
Find a constant in this group by its name
113 114 115 |
# File 'lib/midi-events/constant.rb', line 113 def find(name) @constants.find { |const| Name.match?(const.key, name) } end |
#find_by_value(value) ⇒ MIDIEvents::Constant::Map?
Find a constant in this group by its value (reverse lookup)
125 126 127 |
# File 'lib/midi-events/constant.rb', line 125 def find_by_value(value) @constants.find { |const| Name.match?(const.value, value) } end |