Module: Zencoder::CLI::Helpers
- Included in:
- Auth, Command, Command::Base, Plugin
- Defined in:
- lib/zencoder-cli/helpers.rb
Instance Method Summary collapse
- #ask ⇒ Object
- #confirm(message = "Are you sure you wish to continue? (y/N)?") ⇒ Object
- #display(msg, newline = true) ⇒ Object
- #error(msg) ⇒ Object
- #format_date(date) ⇒ Object
- #home_directory ⇒ Object
- #running_on_a_mac? ⇒ Boolean
- #running_on_windows? ⇒ Boolean
- #truncate(text, *args) ⇒ Object
Instance Method Details
#ask ⇒ Object
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(="Are you sure you wish to continue? (y/N)?") display("#{} ", 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_directory ⇒ Object
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
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
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) = args. .reverse_merge!(:length => 30, :omission => "...") if text l = [:length] - [:omission].mb_chars.length chars = text.mb_chars (chars.length > [:length] ? chars[0...l] + [:omission] : text).to_s end end |