Module: Zencoder::CLI::Helpers

Included in:
Auth, Command, Command::Base, Plugin
Defined in:
lib/zencoder-cli/helpers.rb

Instance Method Summary collapse

Instance Method Details

#askObject



42
43
44
45
46
47
# File 'lib/zencoder-cli/helpers.rb', line 42

def ask
  gets.strip
rescue Interrupt
  puts
  exit
end

#confirm(message = "Are you sure you wish to continue? (y/N)?") ⇒ Object



37
38
39
40
# File 'lib/zencoder-cli/helpers.rb', line 37

def confirm(message="Are you sure you wish to continue? (y/N)?")
  display("#{message} ", false)
  ask.downcase == 'y'
end

#display(msg, newline = true) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/zencoder-cli/helpers.rb', line 23

def display(msg, newline=true)
  if newline
    puts(msg)
  else
    print(msg)
    STDOUT.flush
  end
end

#error(msg) ⇒ Object



32
33
34
35
# File 'lib/zencoder-cli/helpers.rb', line 32

def error(msg)
  STDERR.puts(msg)
  exit 1
end

#format_date(date) ⇒ Object



18
19
20
21
# File 'lib/zencoder-cli/helpers.rb', line 18

def format_date(date)
  date = Time.parse(date) if date.is_a?(String)
  date.strftime("%Y-%m-%d %H:%M %Z")
end

#home_directoryObject



6
7
8
# File 'lib/zencoder-cli/helpers.rb', line 6

def home_directory
  running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
end

#running_on_a_mac?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/zencoder-cli/helpers.rb', line 14

def running_on_a_mac?
  RUBY_PLATFORM =~ /-darwin\d/
end

#running_on_windows?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/zencoder-cli/helpers.rb', line 10

def running_on_windows?
  RUBY_PLATFORM =~ /mswin32|mingw32/
end

#truncate(text, *args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/zencoder-cli/helpers.rb', line 49

def truncate(text, *args)
  options = args.extract_options!
  options.reverse_merge!(:length => 30, :omission => "...")

  if text
    l = options[:length] - options[:omission].mb_chars.length
    chars = text.mb_chars
    (chars.length > options[:length] ? chars[0...l] + options[:omission] : text).to_s
  end
end