diff --git a/Rakefile b/Rakefile index f338c21..b3e1ca3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :build +task default: :build -task :build => [:gen_all_run_types, :spec] +task build: %i[gen_all_run_types spec] desc 'Generate the all_run_types.g.rb file' task :gen_all_run_types do @@ -19,16 +21,17 @@ task :gen_all_run_types do filename_sans_extension = filename[0, filename.length - 3] parts = filename_sans_extension.to_s.downcase.split(/_|\./) run_type = '' - parts.each { |part| + parts.each do |part| run_type += part[0].upcase + part[-(part.length - 1), part.length - 1] - } + end run_type end puts all_run_types.join(' ') # Write run types to the generated file, all_run_types.g.rb template = File.read(File.join(run_types_path, 'all_run_types.template')) - template.gsub!('__RUN_TYPES__', all_run_types.join(' ')) + template.gsub!('__RUN_TYPE_NAMES__', all_run_types.join(' ')) + template.gsub!('__RUN_TYPES__', all_run_types.join(', ')) File.write(File.join(run_types_path, 'all_run_types.g.rb'), template) puts "\e[32mDone\e[0m\n\n" end diff --git a/bin/runbypace b/bin/runbypace new file mode 100644 index 0000000..a3d6f91 --- /dev/null +++ b/bin/runbypace @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +begin + require "bundler/setup" +rescue LoadError +end + +begin + require 'runby_pace' +rescue LoadError + require_relative '../lib/runby_pace' +end + +cli = Runby::Cli.new(ARGV) +exit cli.run \ No newline at end of file diff --git a/lib/runby_pace/cli.rb b/lib/runby_pace/cli.rb new file mode 100644 index 0000000..1b62a77 --- /dev/null +++ b/lib/runby_pace/cli.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'readline' + +module Runby + # Command line interface and REPL for RunbyPace + class Cli + def initialize(args = ARGV) + @args = args + end + + def run + puts 'Runby Pace REPL!' + bnd = binding + while (input = Readline.readline('🏃 ', true)) + begin + result = bnd.eval input + rescue StandardError => e + puts "#{e.class}: #{e.message}" + else + puts result + end + end + end + + def targets(five_k_time, distance_units = :mi) + five_k_time = Runby.sanitize(five_k_time).as(RunbyTime) + puts "\nIf you can run a 5K in #{five_k_time}, your training paces should be:" + RunTypes.all_classes.each do |run_type| + run = run_type.new + puts " #{run.description}: #{run.lookup_pace(five_k_time, distance_units)}" + end + nil + end + + # -- Shortcuts + def d(*args) + Distance.new(*args) + end + + def du(*args) + DistanceUnit.new(*args) + end + + def p(*args) + Pace.new(*args) + end + + def s(*args) + Speed.new(*args) + end + + def t(*args) + RunbyTime.new(*args) + end + end +end \ No newline at end of file diff --git a/lib/runby_pace/run_types/all_run_types.template b/lib/runby_pace/run_types/all_run_types.template index c51b919..0654366 100644 --- a/lib/runby_pace/run_types/all_run_types.template +++ b/lib/runby_pace/run_types/all_run_types.template @@ -4,7 +4,11 @@ module Runby # Encapsulates data and behavior relating to all run types. module RunTypes def self.all - %w(__RUN_TYPES__) + %w[__RUN_TYPE_NAMES__] + end + + def self.all_classes + [__RUN_TYPES__] end end end diff --git a/lib/runby_pace/version.rb b/lib/runby_pace/version.rb index 82ca248..8472b0e 100644 --- a/lib/runby_pace/version.rb +++ b/lib/runby_pace/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Runby - VERSION = "0.6.#{`git rev-list --count HEAD`}" + VERSION = "0.61.#{`git rev-list --count HEAD`}" end