Permalink
Browse files

add WheelSize class

  • Loading branch information...
1 parent 995b4db commit 6c56c3221c978ee7f18f872c38902c6ee40b36d5 @Capncavedan committed Nov 12, 2013
Showing with 47 additions and 20 deletions.
  1. +0 −20 lib/calculator.rb
  2. +29 −0 lib/wheel_size.rb
  3. +1 −0 spec/spec_helper.rb
  4. +17 −0 spec/wheel_size_spec.rb
View
20 lib/calculator.rb
@@ -43,26 +43,6 @@ def gain_ratio(chainring_size, cog_size)
(ratio * 100).to_i/100.0
end
- # def wheel_circumference
- # {
- # "20x1.75" => 1491,
-
- # "700x20c" => 2086,
- # "700x23c" => 2097,
- # "700x25c" => 2105,
- # "700x28c" => 2136,
- # "700x32c" => 2155,
- # "700x35c" => 2168,
- # "700x38c" => 2180,
- # "700x40c" => 2200, # guessing
- # "700x44c" => 2224,
- # "700x50c" => 2293,
- # "700x56c" => 2325,
-
- # "29x2.3" => 2325
- # }[tire_size] || 0
- # end
-
# accepts integer, string, array
# returns a sorted array of integers
def initialize_chainring_sizes(chainring_sizes)
View
29 lib/wheel_size.rb
@@ -0,0 +1,29 @@
+class GearRatio
+
+ class WheelSize
+
+ # accepts a string description, returns mm
+ def self.circumference_of(tire_size)
+ tire_size = tire_size.to_s.gsub(/[\W]/, '')
+ {
+ "20x1.75" => 1491,
+
+ "700x20c" => 2086,
+ "700x23c" => 2097,
+ "700x25c" => 2105,
+ "700x28c" => 2136,
+ "700x32c" => 2155,
+ "700x35c" => 2168,
+ "700x38c" => 2180,
+ "700x40c" => 2200, # guessing
+ "700x44c" => 2224,
+ "700x50c" => 2293,
+ "700x56c" => 2325,
+
+ "29x2.3" => 2325
+ }[tire_size] || 0
+ end
+
+ end
+
+end
View
1 spec/spec_helper.rb
@@ -1 +1,2 @@
require_relative "../lib/calculator.rb"
+require_relative "../lib/wheel_size.rb"
View
17 spec/wheel_size_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe GearRatio::WheelSize do
+
+ describe ".circumference_of" do
+
+ it "works" do
+ GearRatio::WheelSize.circumference_of("700x25c").should be_a(Fixnum)
+ end
+
+ it "works with whitespace etc" do
+ GearRatio::WheelSize.circumference_of("700 X 25c").should be_a(Fixnum)
+ end
+
+ end
+
+end

0 comments on commit 6c56c32

Please sign in to comment.