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.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fitment/tire.rb', line 27

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

Instance Attribute Details

#ratioObject (readonly) Also known as: series, aspect_ratio

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



25
26
27
# File 'lib/fitment/tire.rb', line 25

def ratio
  @ratio
end

#wheel_diameterObject (readonly)

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



25
26
27
# File 'lib/fitment/tire.rb', line 25

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



25
26
27
# File 'lib/fitment/tire.rb', line 25

def width
  @width
end

Class Method Details

.overall_diameter(width_mm, ratio_flt, wheel_in) ⇒ Object

inches



19
20
21
# File 'lib/fitment/tire.rb', line 19

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

.ratio_flt(ratio_int) ⇒ Object



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

def self.ratio_flt(ratio_int)
  ratio_int / 100.0
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



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

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)



58
59
60
# File 'lib/fitment/tire.rb', line 58

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

#od_mmObject



66
67
68
# File 'lib/fitment/tire.rb', line 66

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

#ratio_fltObject



43
44
45
# File 'lib/fitment/tire.rb', line 43

def ratio_flt
  self.class.ratio_flt(@ratio)
end

#sh_inObject



53
54
55
# File 'lib/fitment/tire.rb', line 53

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

#sh_mmObject Also known as: sidewall_height

sidewall height, (mm) and in



48
49
50
# File 'lib/fitment/tire.rb', line 48

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

#to_sObject



39
40
41
# File 'lib/fitment/tire.rb', line 39

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