Class: OggEncode::Parser

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

Class Method Summary collapse

Class Method Details

.make_path(folder) ⇒ Object



8
9
10
# File 'lib/autogg/parser.rb', line 8

def make_path(folder)
  folder =~ /\/$/ ? folder : folder + '/'
end

.parse(args) ⇒ Object



12
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
# File 'lib/autogg/parser.rb', line 12

def parse(args)

  script_name = File.basename( $0 )
  options = OpenStruct.new
  options.max_procs = 4
  options.oggargs = ['-Q']

  op = OptionParser.new do |opts|
    opts.banner = "Usage: autogg.rb [options] flacpath oggpath [ -o oggenc args ... ]\n" +
                  "Example: #{script_name} ~/music/flac/ ~/music/ogg/ --oggenc-args -q8\n" +
                  "    Ex2: #{script_name} ~/music/flac/ ~/music/ogg/ -o -q8,-Q,--utf8"

    opts.on( '-m', '--max-processes n', "Maximum number of encoding processes running at once" ) do |n|
      options.max_procs = n.to_i
    end

    opts.on( '-o', '--oggenc-args arglist', Array,
             "Specify arguments to me be passed through to oggenc" ) do |ary|
      options.oggargs << ary
      options.oggargs.flatten!
    end

    opts.on( '-h', '--help', 'Display this screen' ) do
      puts opts
      puts dirinfo
      exit
    end
  end
  op.parse!

  if ( ARGV.length == 2 ) and ARGV.all? { |a| File.directory?( a )}
    paths = OpenStruct.new
    paths.flac = make_path(ARGV[0]) ; paths.ogg = make_path(ARGV[1])
    options.paths = paths
  else
    puts op
    exit
  end

  options
end