Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Capncavedan/gear-ratio-calculator
base: ac9e4b7a0f
...
head fork: Capncavedan/gear-ratio-calculator
compare: 46936393ec
  • 3 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
4 Gemfile
@@ -1,7 +1,11 @@
source "https://rubygems.org"
+ruby "2.0.0"
+gem "sinatra", "~> 1.4.3"
+gem "sinatra-contrib", "~> 1.4.1"
gem "gruff"
group :test, :development do
+ gem "thin", "~> 1.6.0"
gem "rspec", "~> 2.14.1"
end
View
28 Gemfile.lock
@@ -1,9 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
+ backports (3.3.5)
+ daemons (1.1.9)
diff-lcs (1.2.4)
+ eventmachine (1.0.3)
gruff (0.5.1)
rmagick
+ multi_json (1.8.2)
+ rack (1.5.2)
+ rack-protection (1.5.1)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
rmagick (2.13.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
@@ -13,6 +22,22 @@ GEM
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
+ sinatra (1.4.4)
+ rack (~> 1.4)
+ rack-protection (~> 1.4)
+ tilt (~> 1.3, >= 1.3.4)
+ sinatra-contrib (1.4.1)
+ backports (>= 2.0)
+ multi_json
+ rack-protection
+ rack-test
+ sinatra (~> 1.4.0)
+ tilt (~> 1.3)
+ thin (1.6.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 1.0.0)
+ rack (>= 1.0.0)
+ tilt (1.4.1)
PLATFORMS
ruby
@@ -20,3 +45,6 @@ PLATFORMS
DEPENDENCIES
gruff
rspec (~> 2.14.1)
+ sinatra (~> 1.4.3)
+ sinatra-contrib (~> 1.4.1)
+ thin (~> 1.6.0)
View
36 app.rb
@@ -0,0 +1,36 @@
+ENV['RACK_ENV'] ||= 'development'
+
+require 'sinatra/base'
+require './lib/calculator'
+require './lib/graph'
+require './lib/wheel_size'
+
+class GearRatioCalculatorApp < Sinatra::Base
+ set :show_exceptions, false
+
+ get '/' do
+ p params
+ @chainring_sizes = ""
+ @cog_sizes = ""
+ @crank_length = ""
+ @wheel_circumference = ""
+
+ unless params.empty?
+ @calculator = GearRatio::Calculator.new(chainring_sizes: params[:chainring_sizes],
+ cog_sizes: params[:cog_sizes],
+ crank_length: params[:crank_length],
+ wheel_circumference: params[:wheel_circumference] )
+
+ @chainring_sizes = @calculator.chainring_sizes.join(",")
+ @cog_sizes = @calculator.cog_sizes.join(",")
+ @crank_length = @calculator.crank_length
+ @wheel_circumference = @calculator.wheel_circumference
+
+ @graph = GearRatio::Graph.new(@calculator)
+ @graph.gain_ratio_line_chart
+ end
+
+ erb :index
+ end
+
+end
View
3  config.ru
@@ -0,0 +1,3 @@
+require './app'
+
+run GearRatioCalculatorApp
View
4 lib/calculator.rb
@@ -10,8 +10,8 @@ class Calculator
def initialize(chainring_sizes: nil, cog_sizes: nil, crank_length: nil, wheel_circumference: nil)
self.chainring_sizes = chainring_sizes
self.cog_sizes = cog_sizes
- @crank_length = crank_length
- @wheel_circumference = wheel_circumference
+ @crank_length = crank_length.to_i
+ @wheel_circumference = wheel_circumference.to_i
end
def gain_ratios
View
4 lib/graph.rb
@@ -11,7 +11,7 @@ def gain_ratio_line_chart
g = Gruff::Line.new
g.title = 'Gain Ratios'
hsh = {}
- @calculator.cog_sizes.each_with_index do |c, idx|
+ @calculator.cog_sizes.reverse.each_with_index do |c, idx|
hsh[idx] = c.to_s
end
g.labels = hsh
@@ -19,7 +19,7 @@ def gain_ratio_line_chart
@calculator.chainring_sizes.each_with_index do |chainring_size, idx|
g.data chainring_size.to_s, @calculator.gain_ratios[idx].reverse
end
- g.write('gain_ratios.png')
+ g.write('public/images/gain_ratios.png')
end
end
View
BIN  public/images/gain_ratios.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
67 views/index.erb
@@ -0,0 +1,67 @@
+<html>
+<head>
+ <title>Gain Ratio Calculator</title>
+</head>
+
+<body>
+
+ <h1>Gain Ratio Calculator</h1>
+
+ <form action="/" method="get">
+ <label for="chainring_sizes">Chainring Sizes</label>
+ <input type="text" name="chainring_sizes" id="chainring_sizes" value="<%= @chainring_sizes %>" />
+
+ <br/>
+
+ <label for="cog_sizes">Cog Sizes</label>
+ <input type="text" name="cog_sizes" id="cog_sizes" value="<%= @cog_sizes %>" />
+
+ <br/>
+
+ <label for="crank_length">Crank Arm Length</label>
+ <input type="text" name="crank_length" id="crank_length" value="<%= @crank_length %>" />
+
+ <br/>
+
+ <label for="wheel_circumference">Wheel Circumference</label>
+ <input type="text" name="wheel_circumference" id="wheel_circumference" value="<%= @wheel_circumference %>" />
+
+ <br/>
+ <br/>
+
+ <input type="submit" />
+ </form>
+
+
+ <% unless params.empty? %>
+ <table>
+ <thead>
+ <tr>
+ <th></th>
+ <% @calculator.cog_sizes.reverse.each do |cog_size| %>
+ <th><%= cog_size %></th>
+ <% end %>
+ </tr>
+ </thead>
+
+ <tbody>
+
+ <% @calculator.chainring_sizes.each_with_index do |chainring_size, idx| %>
+ <tr>
+ <th><%= chainring_size %></th>
+ <% @calculator.gain_ratios[idx].each do |gain_ratio| %>
+ <td><%= gain_ratio %></td>
+ <% end %>
+ </tr>
+ <% end %>
+
+ </tbody>
+ </table>
+
+ <br/>
+ <br/>
+
+ <img width="400" height="300" src="/images/gain_ratios.png" />
+ <% end %>
+
+</body>

No commit comments for this range

Something went wrong with that request. Please try again.