triathlon 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,5 @@
1
+ triathlon
2
+ =========
3
+
4
+ ### Interesting triathlon computers.
5
+ Compute some stats and get faster.
data/lib/bike.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'converter'
2
+
3
+ class Bike
4
+ def initialize
5
+ @converter = Converter.new
6
+ end
7
+ def compute_speed(distance, time, *options)
8
+ # todo - could construct with the time unit and thus hold a conversion strategy
9
+ time_in_seconds = time
10
+ unless options.empty?
11
+ options_hash = options[0]
12
+ if options_hash[:time_unit] == :hours
13
+ time_in_seconds = @converter.hours_to_seconds time
14
+ elsif options_hash[:time_unit] == :minutes
15
+ time_in_seconds = @converter.minutes_to_seconds time
16
+ end
17
+ end
18
+
19
+ speed_in_miles_per_second = distance / time_in_seconds
20
+ @converter.mps_to_mph speed_in_miles_per_second
21
+ end
22
+
23
+ def compute_time(distance, speed)
24
+ distance * (60.0 / speed) # assume speed in mph, convert to mpm
25
+ end
26
+ end
27
+
data/lib/converter.rb ADDED
@@ -0,0 +1,13 @@
1
+ class Converter
2
+ SecondsPerHour = 3600
3
+ SecondsPerMinute = 60
4
+ def hours_to_seconds(hours)
5
+ hours * SecondsPerHour
6
+ end
7
+ def minutes_to_seconds(minutes)
8
+ minutes * SecondsPerMinute
9
+ end
10
+ def mps_to_mph(mps)
11
+ mps * SecondsPerHour
12
+ end
13
+ end
data/lib/splits.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'converter'
2
+
3
+ class SplitPresenter
4
+ def initialize(seconds)
5
+ @total_seconds = seconds.to_f
6
+ end
7
+
8
+ def to_s
9
+ if @total_seconds > 3600.0
10
+ return 'NYI'
11
+ end
12
+
13
+ minutes = (@total_seconds / 60.0).round
14
+ seconds = (@total_seconds - (minutes * 60.0)).round
15
+ return "#{minutes}:#{seconds}"
16
+ end
17
+ end
18
+
19
+ class Splits
20
+ def initialize(pace)
21
+ pace_times = pace.split(':').map{|string| string.to_i}
22
+ converter = Converter.new
23
+ if pace_times.size == 3
24
+ @total_pace_in_seconds = converter.hours_to_seconds(pace_times[0]) + converter.minutes_to_seconds(pace_times[1]) + pace_times[2]
25
+ elsif pace_times.size == 2
26
+ @total_pace_in_seconds = converter.minutes_to_seconds(pace_times[0]) + pace_times[1]
27
+ else
28
+ @total_pace_in_seconds = pace_times[0]
29
+ end
30
+ end
31
+
32
+ def getFourHundred()
33
+ return SplitPresenter.new(@total_pace_in_seconds / 4.0)
34
+ end
35
+
36
+ def getEightHundred()
37
+ return SplitPresenter.new(@total_pace_in_seconds / 2.0)
38
+ end
39
+
40
+ def getOneHundred()
41
+ return SplitPresenter.new(@total_pace_in_seconds / 16.0)
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ require 'shoulda'
@@ -0,0 +1,46 @@
1
+ # Test file must be in the test/ directory
2
+ # Test files must be in the form 'test_*.rb'
3
+ # Test class must begin with 'Test'
4
+ # Source: http://yardoc.org/docs/blackwinter-zentest/Autotest
5
+ require 'test_helper'
6
+
7
+ require 'bike'
8
+
9
+ class TestBike < Test::Unit::TestCase
10
+ should "compute bike speed" do
11
+ distance = 14.5
12
+ time = 2400 # default is time in seconds
13
+ bikeRace = Bike.new
14
+ mph = bikeRace.compute_speed distance, time
15
+ expected_mph = 21.75
16
+ assert_in_delta(expected_mph, mph, 0.001)
17
+ end
18
+
19
+ should "compute ride time given speed and distance" do
20
+ distance = 24.8
21
+ speed = 23.0
22
+ bikeRace = Bike.new
23
+ time = bikeRace.compute_time distance, speed
24
+ expected_time = 64.695652173913043
25
+ assert_in_delta(expected_time, time, 0.001)
26
+ end
27
+
28
+ should "compute mph given time in hours" do
29
+ # 75 minutes = 24.8 miles at x miles/hour
30
+ distance = 24.8
31
+ time = 1.25 # 1:15, an hour and fifteen minutes
32
+ bikeRace = Bike.new
33
+ mph = bikeRace.compute_speed(distance, time, :time_unit => :hours)
34
+ expected_mph = 19.84
35
+ assert_in_delta(expected_mph, mph, 0.001)
36
+ end
37
+
38
+ should "compute mph given time in minutes" do
39
+ distance = 14.5
40
+ time = 41.43
41
+ bikeRace = Bike.new
42
+ mph = bikeRace.compute_speed(distance, time, :time_unit => :minutes)
43
+ expected_mph = 21.0
44
+ assert_in_delta(expected_mph, mph, 0.001)
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ require 'converter'
4
+
5
+ class TestConverter < Test::Unit::TestCase
6
+ should "convert hours to seconds" do
7
+ converter = Converter.new
8
+ seconds = converter.hours_to_seconds 1.083333333333333
9
+ expected_seconds = 3900
10
+ assert_in_delta(expected_seconds, seconds, 0.001)
11
+ end
12
+ should "convert minutes to seconds" do
13
+ converter = Converter.new
14
+ seconds = converter.minutes_to_seconds 38.566666666666667
15
+ expected_seconds = 2314
16
+ assert_in_delta(expected_seconds, seconds, 0.001)
17
+ end
18
+ should "convert miles per second to miles per hour" do
19
+ converter = Converter.new
20
+ mps = 0.006805555555556
21
+ mph = converter.mps_to_mph mps
22
+ expected_mph = 24.5
23
+ assert_in_delta(expected_mph, mph, 0.001)
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ require 'splits'
4
+
5
+ class TestSplits < Test::Unit::TestCase
6
+ should 'return split as a string' do
7
+ split = SplitPresenter.new(430)
8
+ assert_equal split.to_s, "7:10"
9
+ end
10
+
11
+ should 'compute 400m pace' do
12
+ splits = Splits.new("10:00")
13
+ fourHundred = splits.getFourHundred
14
+ assert_equal fourHundred.to_s, "2:30"
15
+ end
16
+
17
+ should 'compute 800m pace' do
18
+ splits = Splits.new("6:53")
19
+ eightHundred = splits.getEightHundred
20
+ assert_equal eightHundred.to_s, "3:27"
21
+ end
22
+
23
+ should 'compute 100m pace' do
24
+ splits = Splits.new("5:00")
25
+ oneHundred = splits.getOneHundred
26
+ assert_equal oneHundred.to_s, "0:19"
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: triathlon
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Waylon Calabrese
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-28 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Simple Ruby API to compute various number related to swim, bike, and run training generaly helpful when competing in triathlons.
23
+ email: hiwaylon@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README
32
+ - lib/bike.rb
33
+ - lib/converter.rb
34
+ - lib/splits.rb
35
+ - test/test_helper.rb
36
+ - test/unit/test_bike.rb
37
+ - test/unit/test_converter.rb
38
+ - test/unit/test_splits.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/hiwaylon/triathlon
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Compute interesting stats and get faster.
73
+ test_files: []
74
+