Class: Runby::Cli::Cli
- Inherits:
-
Object
- Object
- Runby::Cli::Cli
- Defined in:
- lib/runby_pace/cli/cli.rb
Overview
Command line interface and REPL for RunbyPace
Instance Method Summary collapse
-
#di(*args) ⇒ Object
– Shortcuts for the REPL.
- #du(*args) ⇒ Object
-
#initialize(args = ARGV) ⇒ Cli
constructor
A new instance of Cli.
- #pc(*args) ⇒ Object
- #print_targets(five_k_time, distance_units = :mi) ⇒ Object
- #run ⇒ Object
- #sp(*args) ⇒ Object
- #tm(*args) ⇒ Object
Constructor Details
Instance Method Details
#di(*args) ⇒ Object
– Shortcuts for the REPL
46 47 48 |
# File 'lib/runby_pace/cli/cli.rb', line 46 def di(*args) Distance.new(*args) end |
#du(*args) ⇒ Object
50 51 52 |
# File 'lib/runby_pace/cli/cli.rb', line 50 def du(*args) DistanceUnit.new(*args) end |
#pc(*args) ⇒ Object
54 55 56 |
# File 'lib/runby_pace/cli/cli.rb', line 54 def pc(*args) Pace.new(*args) end |
#print_targets(five_k_time, distance_units = :mi) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/runby_pace/cli/cli.rb', line 31 def print_targets(five_k_time, distance_units = :mi) five_k_time = @config['five_k_time'] if five_k_time.nil? 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:" paces = [] RunTypes.all_classes.each do |run_type| run = run_type.new paces.push(description: run.description, pace: run.lookup_pace(five_k_time, distance_units)) end paces.sort_by { |p| p[:pace].fast }.reverse_each { |p| puts " #{p[:description]}: #{p[:pace]}" } nil end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/runby_pace/cli/cli.rb', line 17 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.}" else puts result end end end |