Class: MIDIEvents::Constant::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-events/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)


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

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.



44
45
46
# File 'lib/midi-events/constant.rb', line 44

def constants
  @constants
end

#keyObject (readonly)

Returns the value of attribute key.



44
45
46
# File 'lib/midi-events/constant.rb', line 44

def key
  @key
end

Class Method Details

.allArray<ConstantGroup>

All constant groups

Returns:

  • (Array<ConstantGroup>)


70
71
72
73
# File 'lib/midi-events/constant.rb', line 70

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)


78
79
80
81
# File 'lib/midi-events/constant.rb', line 78

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:



56
57
58
# File 'lib/midi-events/constant.rb', line 56

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:



63
64
65
# File 'lib/midi-events/constant.rb', line 63

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