Class: MIDIEvents::ChannelMessage::Accessors

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-events/channel_message.rb

Constant Summary collapse

SCHEMA =
[
  { name: :status, index: 1 }, # second status nibble
  { name: :data, index: 0 }, # first data byte
  { name: :data, index: 1 } # second data byte
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Accessors

Returns a new instance of Accessors.

Parameters:

  • klass (Class)


80
81
82
# File 'lib/midi-events/channel_message.rb', line 80

def initialize(klass)
  @klass = klass
end

Class Method Details

.decorate(klass) ⇒ Class

Parameters:

  • klass (Class)

Returns:

  • (Class)


61
62
63
64
# File 'lib/midi-events/channel_message.rb', line 61

def self.decorate(klass)
  decorator = new(klass)
  decorator.decorate
end

.initialize(message) ⇒ Boolean

Initialize a message object with it's properties

Parameters:

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
# File 'lib/midi-events/channel_message.rb', line 69

def self.initialize(message)
  message.class.properties.each_with_index do |property, i|
    data_mapping = SCHEMA[i]
    container = message.send(data_mapping[:name])
    index = data_mapping[:index]
    message.send(:instance_variable_set, "@#{property.to_s}", container[index])
  end
  true
end

Instance Method Details

#decorateClass

Returns:

  • (Class)


85
86
87
88
89
90
91
92
# File 'lib/midi-events/channel_message.rb', line 85

def decorate
  @klass.properties.each_with_index do |property, i|
    data_mapping = SCHEMA[i]
    define_getter(property)
    define_setter(property, data_mapping)
  end
  @klass
end