class MIDIFX::Limit

Attributes

limit_to[R]
name[R]
property[R]
range[R]

Public Class Methods

new(property, limit_to, options = {}) click to toggle source
# File lib/midi-fx/limit.rb, line 8
def initialize(property, limit_to, options = {})
  @limit_to = limit_to
  @property = property
  @name = options[:name]
end

Public Instance Methods

process(message) click to toggle source
# File lib/midi-fx/limit.rb, line 14
def process(message)
  val = message.send(@property)
  if @limit_to.kind_of?(Range)
    message.send("#{@property}=", @limit_to.min) if val < @limit_to.min
    message.send("#{@property}=", @limit_to.max) if val > @limit_to.max
  elsif @limit_to.kind_of?(Numeric)
    message.send("#{@property}=", @limit_to)
  end
  message
end