Class: Fitment::Wheel
- Inherits:
-
Object
- Object
- Fitment::Wheel
- Defined in:
- lib/fitment/wheel.rb
Instance Attribute Summary collapse
-
#diameter ⇒ Object
readonly
Returns the value of attribute diameter.
-
#et ⇒ Object
readonly
Returns the value of attribute et.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #et! ⇒ Object
-
#initialize(diameter_in, width_in, et: 0, offset: nil) ⇒ Wheel
constructor
A new instance of Wheel.
- #offset! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(diameter_in, width_in, et: 0, offset: nil) ⇒ Wheel
Returns a new instance of Wheel.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fitment/wheel.rb', line 15 def initialize(diameter_in, width_in, et: 0, offset: nil) @diameter = Rational(diameter_in) @width = Rational(width_in) if offset @et = nil @offset = Rational(offset) else @offset = nil @et = et.to_i end end |
Instance Attribute Details
#diameter ⇒ Object (readonly)
Returns the value of attribute diameter.
13 14 15 |
# File 'lib/fitment/wheel.rb', line 13 def diameter @diameter end |
#et ⇒ Object (readonly)
Returns the value of attribute et.
13 14 15 |
# File 'lib/fitment/wheel.rb', line 13 def et @et end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
13 14 15 |
# File 'lib/fitment/wheel.rb', line 13 def offset @offset end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/fitment/wheel.rb', line 13 def width @width end |
Class Method Details
.et(offset_in, width_in) ⇒ Object
5 6 7 |
# File 'lib/fitment/wheel.rb', line 5 def self.et(offset_in, width_in) (-1 * Fitment.mm(offset_in - width_in / 2)).round end |
.offset(et_mm, width_in) ⇒ Object
9 10 11 |
# File 'lib/fitment/wheel.rb', line 9 def self.offset(et_mm, width_in) (width_in / 2 - Fitment.inches(et_mm)).round(2) end |
Instance Method Details
#et! ⇒ Object
27 28 29 |
# File 'lib/fitment/wheel.rb', line 27 def et! @et or self.class.et(@offset, @width) end |
#offset! ⇒ Object
31 32 33 |
# File 'lib/fitment/wheel.rb', line 31 def offset! @offset or self.class.offset(@et, @width) end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/fitment/wheel.rb', line 35 def to_s ary = ["%gx%g" % [@diameter, @width]] if @offset ary << "offset:%g" % @offset else ary << "et:%i" % @et end ary.join(' ') end |