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.



17
18
19
20
# File 'lib/midi-message/constant.rb', line 17

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



15
16
17
# File 'lib/midi-message/constant.rb', line 15

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



15
16
17
# File 'lib/midi-message/constant.rb', line 15

def value
  @value
end

Class Method Details

.[](key) ⇒ ConstantGroup

Find a constant group by its key

Parameters:

  • key (String, Symbol)

Returns:

  • (ConstantGroup)


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

def self.[](key)
  ensure_initialized
  @groups.find { |g| g.key.to_s.downcase == key.to_s.downcase }
end

.allArray<ConstantGroup>

All constant groups

Returns:

  • (Array<ConstantGroup>)


39
40
41
42
# File 'lib/midi-message/constant.rb', line 39

def self.all
  ensure_initialized
  @groups
end

Instance Method Details

#find(name) ⇒ Constant::Map Also known as: []

Find a constant by its name

Parameters:

  • name (String, Symbol)

Returns:



25
26
27
# File 'lib/midi-message/constant.rb', line 25

def find(name)
  @constants.find { |const| const.key.to_s.downcase == name.to_s.downcase }
end

#find_by_value(value) ⇒ Constant::Map

Find a constant by its value

Parameters:

  • value (Object)

Returns:



33
34
35
# File 'lib/midi-message/constant.rb', line 33

def find_by_value(value)
  @constants.find { |const| const.value.to_s.downcase == value.to_s.downcase }
end