Class: MIDIEvents::ChannelMessage::Accessors
- Inherits:
-
Object
- Object
- MIDIEvents::ChannelMessage::Accessors
- 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
- .decorate(klass) ⇒ Class
-
.initialize(message) ⇒ Boolean
Initialize a message object with it's properties.
Instance Method Summary collapse
- #decorate ⇒ Class
-
#initialize(klass) ⇒ Accessors
constructor
A new instance of Accessors.
Constructor Details
#initialize(klass) ⇒ Accessors
Returns a new instance of Accessors.
80 81 82 |
# File 'lib/midi-events/channel_message.rb', line 80 def initialize(klass) @klass = klass end |
Class Method Details
.decorate(klass) ⇒ 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
69 70 71 72 73 74 75 76 77 |
# File 'lib/midi-events/channel_message.rb', line 69 def self.initialize() .class.properties.each_with_index do |property, i| data_mapping = SCHEMA[i] container = .send(data_mapping[:name]) index = data_mapping[:index] .send(:instance_variable_set, "@#{property.to_s}", container[index]) end true end |
Instance Method Details
#decorate ⇒ 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 |