Skip to content

Instantly share code, notes, and snippets.

@xbony2
Created June 9, 2019 13:34
Show Gist options
  • Save xbony2/28908b42ec3851c6141787dd81ff1bbf to your computer and use it in GitHub Desktop.
Save xbony2/28908b42ec3851c6141787dd81ff1bbf to your computer and use it in GitHub Desktop.
Coabot
##
# It's like a coach, but it's a bot
# @author Eric Schenider
require 'yaml'
puts "Thank you for using Coabot. But first, an inspiring quote from a coach..."
puts
quotes = ["Work harder!", "Act like you really want to be on the team!", "Act like you're serious!", "RUN FASTER!", "MOVE IT!", "If you're going to go that slow anyway, what's the point in running?"]
puts "\"" + quotes[rand(quotes.length)] + "\""
puts
##
# Represents a workout.
# @author Eric Schenider
class Workout
attr_accessor :difficulty, :name, :description, :core
@@workouts = []
def self.workouts
@@workouts
end
##
# Creates a Workout object
#
# @param [Symbol] difficulty The difficulty of the workout. Valid inputs are :easy, :medium, :hard
# @param [String] name The name of the workout.
# @param [String] description A description for the workout.
# @param [Int] core The chance of having core, out of 100
#
# @author Eric Schenider
def initialize(difficulty, name, description, core)
@difficulty = difficulty
@name = name
@description = description
@core = core
@@workouts.push(self)
end
def display
ret = "#{@name}: #{@description} (#{@difficulty})."
ret += " Includes core." if (rand(99) + 1) < @core
ret
end
end
YAML.load(File.read("workouts.yml")).each do |name, workout|
Workout.new(workout["difficulty"].to_sym, name, workout["description"], workout["core"])
end
def generate_workout(difficulty)
ret = Workout.workouts.clone.keep_if do |workout|
workout.difficulty == difficulty
end
ret[rand(ret.length)]
end
{"Monday" => :hard, "Tuesday" => :easy, "Wednesday" => :medium, "Thursday" => :hard, "Friday" => :medium, "Saturday" => :easy}.each do |day, difficulty|
puts "#{day}: #{generate_workout(difficulty).display}"
puts
end
30 min:
difficulty: easy
description: A simple run
core: 100
40 min:
difficulty: easy
description: A simple run
core: 90
50 min:
difficulty: easy
description: A simple run
core: 80
4x400 + 6x200:
difficulty: easy
description: Run four 400m at mile race pace (equal rest), take a five minute break, and then run six 200m at 800m race pace (equal rest)
core: 80
55 min:
difficulty: medium
description: A simple run
core: 80
60 min:
difficulty: medium
description: A simple run
core: 60
70 min:
difficulty: medium
description: A simple run
core: 40
10 Hills:
difficulty: medium
description: Run up the Gravel Hill and jog down it ten times.
core: 50
"8x2:2 min Fartlek":
difficulty: medium
description: Run at 2 mile race pace for 2 minutes, and then run a slow pace for 2 minutes, and do this 8 times.
core: 50
75 min:
difficulty: hard
description: A simple run
core: 50
80 min:
difficulty: hard
description: A simple run
core: 30
90 min:
difficulty: hard
description: A simple run
core: 10
100 min:
difficulty: hard
description: A simple run
core: 5
16 Hills:
difficulty: hard
description: Run up the Gravel Hill and jog down it sixteen times.
core: 30
16x300:
difficulty: hard
description: Run sixteen 300m at 2 mile race pace (equal rest).
core: 10
16x400:
difficulty: hard
description: Run sixteen 400m at 2 mile race pace (equal rest).
core: 5
8x800:
difficulty: hard
description: Run eight 800m at slightly slowly than mile race pace (equal rest).
core: 5
8x400 + 10x300:
difficulty: hard
description: Run eight 400m at mile race pace (equal rest), and then run ten 300m at mile race pace (equal rest)
core: 5
"10x2:2 min Fartlek":
difficulty: hard
description: Run at 2 mile race pace for 2 minutes, and then run a slow pace for 2 minutes, and do this 10 times.
core: 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment