Class: Smt::Options

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

Constant Summary collapse

<<~BANNER
  Usage: smt [options]
BANNER

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



9
10
# File 'lib/smt/options.rb', line 9

def initialize
end

Instance Method Details

#for_parseObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/smt/options.rb', line 38

def for_parse
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: smt [options]"

    help_opts(opts)
    time_opts(opts)
    format_opts(opts)
    list_opts(opts)
  end

  {
    parser: parser, input: @input, format: @format
  }
end

#format_opts(opts) ⇒ Object



18
19
20
21
22
# File 'lib/smt/options.rb', line 18

def format_opts(opts)
  opts.on("-f", "--format FORMAT", "Time format") do |fmt|
    @format = fmt
  end
end

#help_opts(opts) ⇒ Object



24
25
26
27
28
29
# File 'lib/smt/options.rb', line 24

def help_opts(opts)
  opts.on("-h", "--help", "Display this screen") do
    puts opts
    exit
  end
end

#list_opts(opts) ⇒ Object



31
32
33
34
35
36
# File 'lib/smt/options.rb', line 31

def list_opts(opts)
  opts.on("-l", "--list", "List all timezones") do
    puts ActiveSupport::TimeZone.all.map(&:name)
    exit
  end
end

#parse!Object



53
54
55
56
57
58
59
# File 'lib/smt/options.rb', line 53

def parse!
  for_parse[:parser].parse!

  [
    for_parse[:input], for_parse[:format]
  ]
end

#time_opts(opts) ⇒ Object



12
13
14
15
16
# File 'lib/smt/options.rb', line 12

def time_opts(opts)
  opts.on("-t", "--time TIME", "Time to convert") do |time|
    @input = time
  end
end