class Util

Public Class Methods

new(debug) click to toggle source
# File lib/util.rb, line 2
def initialize(debug)
  @debug = debug
end

Public Instance Methods

check_affirmative() click to toggle source
# File lib/util.rb, line 32
def check_affirmative
  ans = ['y', 'yes', ''].include?(gets.chomp) ? true : false
  dbg("affirmative = #{ans}")
  puts "\n"
  return ans
end
dbg(msg) click to toggle source
# File lib/util.rb, line 16
def dbg(msg)
  if @debug
    puts "debug: #{msg}".blue
  end
end
debug_bottom() click to toggle source
# File lib/util.rb, line 12
def debug_bottom
  "#{('-'*80).blue}"
end
debug_top(data) click to toggle source
# File lib/util.rb, line 7
def debug_top(data)
  "\n\n\n#{('-'*80).blue}\n#{'raw data:'.yellow}\n#{data.inspect.yellow}\n\n#{'formatted:'.green}\n"
end
decrypt(s) click to toggle source
# File lib/util.rb, line 73
def decrypt(s)
  if s
    carr = []
    s.chomp.each_byte do |c|
      (33..126).to_a.include?(c - 20) ? carr << (c - 20).chr : carr << (c - 20 + 94).chr
    end
    carr.join
  else
    ''
  end
end
display_data(header, data) click to toggle source
# File lib/util.rb, line 22
def display_data(header, data)
  if @debug then puts debug_top(data) end
    
  data.split(/\r\n?/).each do |line|
    puts format_line(header, line)
  end

  if @debug then puts debug_bottom end
end
display_error(error) click to toggle source
# File lib/util.rb, line 45
def display_error(error)
  if @debug
    puts error.backtrace
    puts error
  end
end
encrypt(s) click to toggle source
# File lib/util.rb, line 59
def encrypt(s)
  if s
    ecarr = []
    s.chomp.each_byte do |c|
      (33..126).to_a.include?(c + 20) ? ecarr << (c + 20).chr : ecarr << (c + 20 - 94).chr
    end
    ecarr.join
  else
    ''
  end
end
format_line(header, line) click to toggle source
# File lib/util.rb, line 39
def format_line(header, line)
  if not line.chomp.empty?
    "#{header.blue}#{line}"
  end
end
show_summary(worker) click to toggle source
# File lib/util.rb, line 53
def show_summary(worker)
  if @debug
    puts "\n\n#{worker.to_s.blue}\n"
  end
end