Module: RTanque::NormalizedAttr

Included in:
Bot, Bot::Radar, Bot::Turret
Defined in:
lib/rtanque/normalized_attr.rb

Defined Under Namespace

Classes: AttrContainer

Constant Summary

MAX_DELTA =

INFINITY

1.0 / 0.0

Instance Method Summary collapse

Instance Method Details

#attr_normalized(attr_name, range, max_delta = MAX_DELTA) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# 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) ⇒ Object



15
16
17
# File 'lib/rtanque/normalized_attr.rb', line 15

def normalized_attrs(attr_name)
  @_normalized_attrs.fetch(attr_name)
end