module RTanque::NormalizedAttr

Constants

MAX_DELTA

Public Instance Methods

attr_normalized(attr_name, range, max_delta = MAX_DELTA) click to toggle source
# File lib/rtanque/normalized_attr.rb, line 4
def attr_normalized(attr_name, range, max_delta = MAX_DELTA)
  @_normalized_attrs ||= {}
  @_normalized_attrs[attr_name] = AttrContainer.new(range, max_delta)
  const_set("MAX_#{attr_name.to_s.upcase}", @_normalized_attrs[attr_name].max)
  const_set("MIN_#{attr_name.to_s.upcase}", @_normalized_attrs[attr_name].min)
  define_method("normalize_#{attr_name}") do |current_value, new_value|
    return new_value unless new_value
    self.class.normalized_attrs(attr_name).normalize(self, current_value, new_value)
  end
end
normalized_attrs(attr_name) click to toggle source
# File lib/rtanque/normalized_attr.rb, line 15
def normalized_attrs(attr_name)
  @_normalized_attrs.fetch(attr_name)
end