Class: WGif::ArgumentParser
- Inherits:
-
Object
- Object
- WGif::ArgumentParser
- Defined in:
- lib/wgif/argument_parser.rb
Constant Summary collapse
- DEFAULTS =
{ trim_from: '00:00:00', duration: 1.0, dimensions: '480' }
Instance Method Summary collapse
- #argument_summary ⇒ Object
-
#initialize ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #parse(args) ⇒ Object
- #parse_args(args) ⇒ Object
- #parse_options(args) ⇒ Object
- #print_help ⇒ Object
- #print_version ⇒ Object
- #validate(args) ⇒ Object
Constructor Details
#initialize ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
# File 'lib/wgif/argument_parser.rb', line 13 def initialize @options = {} @parser = OptionParser.new do |opts| opts.on('-f N', '--frames N', 'Number of frames in the final gif. (Default 20)') { |n| @options[:frames] = n.to_i } opts.on('-s HH:MM:SS.SSSS', '--start HH:MM:SS.SSSS', 'Start creating gif from input video at this timestamp. (Default 00:00:00)') { |ts| @options[:trim_from] = ts } opts.on('-d seconds', '--duration seconds', 'Number of seconds of input video to capture. (Default 1.0)') { |d| @options[:duration] = d.to_f } opts.on('-w pixels', '--width pixels', 'Width of the gif in pixels. (Default 480px)') { |gs| @options[:dimensions] = gs } opts.on('-u', '--upload', 'Upload finished gif to Imgur') { |u| @options[:upload] = u } opts.on('-i', '--info', 'Displays info about finished gif (currently just file size)') { |i| @options[:info] = i } opts.on('-p', '--preview', 'Preview finished gif with Quick Look') { |p| @options[:preview] = p } opts.on_tail('-h', '--help', 'Print help information.') { print_help exit } opts.on_tail('-v', '--version', 'Print version.') { print_version exit } end end |
Instance Method Details
#argument_summary ⇒ Object
76 77 78 |
# File 'lib/wgif/argument_parser.rb', line 76 def argument_summary @parser.summarize end |
#parse(args) ⇒ Object
66 67 68 69 70 |
# File 'lib/wgif/argument_parser.rb', line 66 def parse(args) = parse_args(args) validate() end |
#parse_args(args) ⇒ Object
80 81 82 83 |
# File 'lib/wgif/argument_parser.rb', line 80 def parse_args(args) = DEFAULTS.merge( args) .merge(url: args[0], output: args[1]) end |
#parse_options(args) ⇒ Object
85 86 87 88 |
# File 'lib/wgif/argument_parser.rb', line 85 def (args) @parser.parse! args @options end |
#print_help ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/wgif/argument_parser.rb', line 94 def print_help puts 'Usage: wgif [YouTube URL] [output file] [options]', "\n" puts argument_summary, "\n" puts <<-example Example: $ wgif https://www.youtube.com/watch?v=1A78yTvIY1k bjork.gif -s 00:03:30 -d 2.2 -w 400 --upload example end |