Module: VMCExtensions
- Included in:
- Object
- Defined in:
- lib/cli/core_ext.rb
Instance Method Summary collapse
- #banner(message) ⇒ Object
- #blank? ⇒ Boolean
- #clear(size = 80) ⇒ Object
- #display(message, nl = true) ⇒ Object
- #err(message, prefix = 'Error: ') ⇒ Object
- #header(message, filler = '-') ⇒ Object
- #pretty_size(size, prec = 1) ⇒ Object
- #quit(message = nil) ⇒ Object
- #say(message) ⇒ Object
- #uptime_string(delta) ⇒ Object
- #warn(msg) ⇒ Object
Instance Method Details
#banner(message) ⇒ Object
13 14 15 16 |
# File 'lib/cli/core_ext.rb', line 13 def () say "\n" say end |
#blank? ⇒ Boolean
49 50 51 |
# File 'lib/cli/core_ext.rb', line 49 def blank? self.to_s.blank? end |
#clear(size = 80) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/cli/core_ext.rb', line 29 def clear(size=80) return unless VMC::Cli::Config.output VMC::Cli::Config.output.print("\r") VMC::Cli::Config.output.print(" " * size) VMC::Cli::Config.output.print("\r") #VMC::Cli::Config.output.flush end |
#display(message, nl = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cli/core_ext.rb', line 18 def display(, nl=true) if nl say else if VMC::Cli::Config.output VMC::Cli::Config.output.print() VMC::Cli::Config.output.flush end end end |
#err(message, prefix = 'Error: ') ⇒ Object
37 38 39 |
# File 'lib/cli/core_ext.rb', line 37 def err(, prefix='Error: ') raise VMC::Cli::CliExit, "#{prefix}#{}" end |
#header(message, filler = '-') ⇒ Object
7 8 9 10 11 |
# File 'lib/cli/core_ext.rb', line 7 def header(, filler = '-') say "\n" say say filler.to_s * .size end |
#pretty_size(size, prec = 1) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cli/core_ext.rb', line 64 def pretty_size(size, prec=1) return 'NA' unless size return "#{size}B" if size < 1024 return sprintf("%.#{prec}fK", size/1024.0) if size < (1024*1024) return sprintf("%.#{prec}fM", size/(1024.0*1024.0)) if size < (1024*1024*1024) return sprintf("%.#{prec}fG", size/(1024.0*1024.0*1024.0)) end |
#quit(message = nil) ⇒ Object
45 46 47 |
# File 'lib/cli/core_ext.rb', line 45 def quit( = nil) raise VMC::Cli::GracefulExit, end |
#say(message) ⇒ Object
3 4 5 |
# File 'lib/cli/core_ext.rb', line 3 def say() VMC::Cli::Config.output.puts() if VMC::Cli::Config.output end |
#uptime_string(delta) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cli/core_ext.rb', line 53 def uptime_string(delta) num_seconds = delta.to_i days = num_seconds / (60 * 60 * 24); num_seconds -= days * (60 * 60 * 24); hours = num_seconds / (60 * 60); num_seconds -= hours * (60 * 60); minutes = num_seconds / 60; num_seconds -= minutes * 60; "#{days}d:#{hours}h:#{minutes}m:#{num_seconds}s" end |
#warn(msg) ⇒ Object
41 42 43 |
# File 'lib/cli/core_ext.rb', line 41 def warn(msg) say "#{"[WARNING]".yellow} #{msg}" end |