Class: Runby::Cli::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/runby_pace/cli/cli.rb

Overview

Command line interface and REPL for RunbyPace

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
# File 'lib/runby_pace/cli/cli.rb', line 11

def initialize(args = ARGV)
  @args = args
  @config = Config.new
  @options = parse_options args
end

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


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

#runObject



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.message}"
    else
      puts result
    end
  end
end

#sp(*args) ⇒ Object



58
59
60
# File 'lib/runby_pace/cli/cli.rb', line 58

def sp(*args)
  Speed.new(*args)
end

#tm(*args) ⇒ Object



62
63
64
# File 'lib/runby_pace/cli/cli.rb', line 62

def tm(*args)
  RunbyTime.new(*args)
end