Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move total_distance.rb out of command plist into a .rb file for easie…

…r editing.
  • Loading branch information...
commit 7042c50f243e693c9f8ec1a6e5b0f0af31933352 1 parent efa2688
@sewm authored
Showing with 44 additions and 44 deletions.
  1. +1 −44 Commands/Total Distance.tmCommand
  2. +43 −0 Support/bin/total_distance.rb
View
45 Commands/Total Distance.tmCommand
@@ -5,50 +5,7 @@
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
- <string>#!/usr/bin/ruby
-
-require 'rexml/document'
-include REXML
-
-DIRECTORY = "/Users/sam/Documents/Fitness/Workouts"
-
-total_distance, total_2009, total_2010, total_2011 = 0.00, 0.00, 0.00, 0.00
-total_rides, total_rides_2009, total_rides_2010, total_rides_2011 = 0, 0, 0, 0
-
-Dir.glob(DIRECTORY + "/*.xml") do |file|
- year = file.match(/20\d\d/).to_s
-
- xml = Document.new(File.open(file))
-
- distance = XPath.first(xml, "//distance")
- if distance
- d = distance.text.to_f
-
- total_distance += d
- total_rides += 1
-
- case year
- when "2009"
- total_2009 += d
- total_rides_2009 += 1
- when "2010"
- total_2010 += d
- total_rides_2010 += 1
- when "2011"
- total_2011 += d
- total_rides_2011 += 1
- else
- puts "&lt;p&gt;Add case for #{year}&lt;/p&gt;"
- end
-
- end
-end
-
-puts "&lt;p&gt;Total Distance: #{total_distance} km in #{total_rides} rides.&lt;/p&gt;"
-puts "&lt;p&gt;Total Distance for 2009: #{total_2009} km in #{total_rides_2009} rides.&lt;/p&gt;"
-puts "&lt;p&gt;Total Distance for 2010: #{total_2010} km in #{total_rides_2010} rides.&lt;/p&gt;"
-puts "&lt;p&gt;Total Distance for 2011: #{total_2011} km in #{total_rides_2011} rides.&lt;/p&gt;"
-</string>
+ <string>total_distance.rb</string>
<key>fallbackInput</key>
<string>document</string>
<key>input</key>
View
43 Support/bin/total_distance.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+
+require 'rexml/document'
+include REXML
+
+DIRECTORY = "/Users/sam/Documents/Fitness/Workouts"
+
+total_distance, total_2009, total_2010, total_2011 = 0.00, 0.00, 0.00, 0.00
+total_rides, total_rides_2009, total_rides_2010, total_rides_2011 = 0, 0, 0, 0
+
+Dir.glob(DIRECTORY + "/*.xml") do |file|
+ year = file.match(/20\d\d/).to_s
+
+ xml = Document.new(File.open(file))
+
+ distance = XPath.first(xml, "//distance")
+ if distance
+ d = distance.text.to_f
+
+ total_distance += d
+ total_rides += 1
+
+ case year
+ when "2009"
+ total_2009 += d
+ total_rides_2009 += 1
+ when "2010"
+ total_2010 += d
+ total_rides_2010 += 1
+ when "2011"
+ total_2011 += d
+ total_rides_2011 += 1
+ else
+ puts "<p>Add case for #{year}</p>"
+ end
+
+ end
+end
+
+puts "<p>Total Distance: #{total_distance} km in #{total_rides} rides.</p>"
+puts "<p>Total Distance for 2009: #{total_2009} km in #{total_rides_2009} rides.</p>"
+puts "<p>Total Distance for 2010: #{total_2010} km in #{total_rides_2010} rides.</p>"
+puts "<p>Total Distance for 2011: #{total_2011} km in #{total_rides_2011} rides.</p>"

0 comments on commit 7042c50

Please sign in to comment.
Something went wrong with that request. Please try again.