Class: Smt::Options
- Inherits:
-
Object
- Object
- Smt::Options
- Defined in:
- lib/smt/options.rb
Constant Summary collapse
- BANNER =
<<~BANNER Usage: smt [options] BANNER
Instance Method Summary collapse
- #for_parse ⇒ Object
- #format_opts(opts) ⇒ Object
- #help_opts(opts) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #list_opts(opts) ⇒ Object
- #parse! ⇒ Object
- #time_opts(opts) ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
9 10 |
# File 'lib/smt/options.rb', line 9 def initialize end |
Instance Method Details
#for_parse ⇒ Object
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. = "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 |