Class: Command

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = []) ⇒ Command

Returns a new instance of Command.



30
31
32
# File 'lib/shunkuntype.rb', line 30

def initialize(argv=[])
  @argv = argv
end

Class Method Details

.run(argv = []) ⇒ Object



26
27
28
# File 'lib/shunkuntype.rb', line 26

def self.run(argv=[])
  new(argv).execute
end

Instance Method Details

#executeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/shunkuntype.rb', line 34

def execute
  DataFiles.prepare

  @mode = nil

  command_parser = OptionParser.new do |opt|
    opt.on('-v', '--version','show program Version.') { |v|
      opt.version = Shunkuntype::VERSION
      puts opt.ver
    }
    opt.on('-c', '--check','Check speed') {|v| SpeedCheck.new }
    opt.on('-d', '--drill [VAL]','one minute Drill [VAL]', Integer) {|v| Training.new(v) }
    opt.on('-h', '--help','show help message') { puts opt; exit }
    opt.on('-l','--log','view training log') {|v| FinishCheck.new }
    opt.on('-r MODE', '--record MODE',
      "Show record data in readable format.\n" \
      "  MODE can be:\n" \
      "  all           Show both speed and training data (default)\n" \
      "  plot          Output matplotlib code for plotting\n" \
      "  speed_data    Show only speed data\n" \
      "  training_data Show only training data"
    ) {|mode| @mode = mode }
#      opt.on('-r', '--record', 'Show both speed and training data (same as -r all)') { @mode = 'all' }
  end
  command_parser.parse!(@argv)
  # データ表示
  case @mode
  when 'plot', 'python'
    print_python_plot_code
    exit
  when 'speed_data'
    print_csv_pretty(Shunkuntype::SPEED_FILE, %w[Time Words TimeSec Score])
    exit
  when 'training_data'
    print_csv_pretty(Shunkuntype::TRAINING_FILE, %w[Time Words TimeSec Score])
    exit
  when 'all'
    print_pretty_data
    exit
  end

  @argv << '--help' if @argv.size==0
  command_parser.parse!(@argv)
  exit
end