Class: Uac::UacPrivate

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

Instance Method Summary collapse

Instance Method Details

#encode_arg(arg) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/uac.rb', line 8

def encode_arg arg
  s = arg.gsub /(\\+)"/, "#{$1}#{$1}\""
  s = s.gsub /(\\+)$"/, "#{$1}#{$1}"
  if s.match /\s/
    s = "\"" + s + "\""
  end
  return s
end

#get_long_arg(args) ⇒ Object



17
18
19
20
21
# File 'lib/uac.rb', line 17

def get_long_arg args
  return args.map do |arg|
    encode_arg arg
  end.join " "
end

#join_args(options, args) ⇒ Object



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
# File 'lib/uac.rb', line 37

def join_args options, args
  if options[:terminal]
    file = "cmd"
    rest_args = args
  else
    file = args[0]
    rest_args = args[1..-1]
  end

  rest = get_long_arg rest_args

  if options[:cd]
    pre = get_long_arg [ 'cd', '/d', Dir.pwd, '&' ]
    rest = join_long_args [ pre, rest ]
  end

  if options[:pause]
    post = get_long_arg([ '&', 'pause' ])
    rest = join_long_args [ rest, post ]
  end

  if options[:terminal]
    rest = "/c \"#{rest}\""
  end

  if options[:debug]
    puts "file: #{file}"
    puts "rest: #{rest}"
  end

  return [file, rest]
end

#join_long_args(args, separator = " ") ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uac.rb', line 23

def join_long_args args, separator = " "
  result = []
  for arg in args
    m = arg.match /^"(.+?)"$/
    if m
      core = m.captures[0]
    else
      core = arg
    end
    result << core
  end
  return result.join separator
end