Skip to content

Instantly share code, notes, and snippets.

@romuloceccon
Last active July 19, 2016 12:59
Show Gist options
  • Select an option

  • Save romuloceccon/b2b1cb41fbe0a9767606de51d43eda2c to your computer and use it in GitHub Desktop.

Select an option

Save romuloceccon/b2b1cb41fbe0a9767606de51d43eda2c to your computer and use it in GitHub Desktop.
Convert Hal Higdon training plans from miles to km (http://halhigdon.com/training/51135/Marathon-Training-Guide/)
require 'csv'
CSV do |out|
csv = CSV.new(STDIN)
csv.each do |row|
out << row.map do |x|
if m = x.match(/^\d+$/)
(m[0].to_i * 1.6).round.to_s
elsif m = x.match(/^(\d+)( m)(.*)$/)
(m[1].to_i * 1.6).round.to_s + ' km' + m[3]
else
x
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment