Class: Fitment::Tire

Inherits:
Object
  • Object
show all
Defined in:
lib/fitment/tire.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width_mm, ratio, wheel_in) ⇒ Tire

Returns a new instance of Tire.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fitment/tire.rb', line 23

def initialize(width_mm, ratio, wheel_in)
  @width = width_mm
  if ratio < 0.99 and ratio > 0.1
    @series = self.class.ratio_int(ratio)
  elsif ratio.is_a? Integer and ratio%5 == 0 and ratio > 10 and ratio < 99
    @series = ratio
  else
    raise("unexpected ratio: #{ratio}")
  end
  @ratio = Rational(@series, 100)
  @wheel_diameter = wheel_in
end

Instance Attribute Details

#ratioObject (readonly) Also known as: aspect_ratio

the aspect ratio is stored as an integer for easy assignment and comparison, and converted to a float for calculations



21
22
23
# File 'lib/fitment/tire.rb', line 21

def ratio
  @ratio
end

#seriesObject (readonly)

the aspect ratio is stored as an integer for easy assignment and comparison, and converted to a float for calculations



21
22
23
# File 'lib/fitment/tire.rb', line 21

def series
  @series
end

#wheel_diameterObject (readonly)

the aspect ratio is stored as an integer for easy assignment and comparison, and converted to a float for calculations



21
22
23
# File 'lib/fitment/tire.rb', line 21

def wheel_diameter
  @wheel_diameter
end

#widthObject (readonly)

the aspect ratio is stored as an integer for easy assignment and comparison, and converted to a float for calculations



21
22
23
# File 'lib/fitment/tire.rb', line 21

def width
  @width
end

Class Method Details

.overall_diameter(width_mm, ratio_flt, wheel_in) ⇒ Object

inches



15
16
17
# File 'lib/fitment/tire.rb', line 15

def self.overall_diameter(width_mm, ratio_flt, wheel_in)
  2 * Fitment.inches(sidewall_height(width_mm, ratio_flt)) + wheel_in
end

.ratio_int(ratio_flt) ⇒ Object



5
6
7
# File 'lib/fitment/tire.rb', line 5

def self.ratio_int(ratio_flt)
  (ratio_flt * 100.0 / 5).round * 5
end

.sidewall_height(width_mm, ratio_flt) ⇒ Object

mm



10
11
12
# File 'lib/fitment/tire.rb', line 10

def self.sidewall_height(width_mm, ratio_flt)
  width_mm * ratio_flt
end

Instance Method Details

#od_inObject Also known as: overall_diameter

overall diameter, mm and (in)



51
52
53
# File 'lib/fitment/tire.rb', line 51

def od_in
  self.class.overall_diameter(@width, @ratio, @wheel_diameter).round(2)
end

#od_mmObject



56
57
58
# File 'lib/fitment/tire.rb', line 56

def od_mm
  Fitment.mm(od_in).round(1)
end

#sh_inObject



46
47
48
# File 'lib/fitment/tire.rb', line 46

def sh_in
  Fitment.inches(sh_mm).round(2)
end

#sh_mmObject Also known as: sidewall_height

sidewall height, (mm) and in



41
42
43
# File 'lib/fitment/tire.rb', line 41

def sh_mm
  self.class.sidewall_height(@width, @ratio).round(1)
end

#to_sObject



36
37
38
# File 'lib/fitment/tire.rb', line 36

def to_s
  [[@width, @series].join('/'), @wheel_diameter].join('R')
end