module CommonStuff

Public Instance Methods

choose_file() click to toggle source
# File lib/common_stuff.rb, line 52
def choose_file
  puts #formatting
  puts "Please enter the full path to the spreadsheet(s):"
  prompt; gets.chomp
end
fill_hash(work_dir, batchy, auto_mater) click to toggle source
# File lib/common_stuff.rb, line 58
def fill_hash work_dir, batchy, auto_mater
  cur_conf = Hash.new
  cur_conf[:work_dir]     = work_dir
  cur_conf[:batchy]       = batchy
  cur_conf[:auto_mater]   = auto_mater
  cur_conf
end
load_config() click to toggle source
# File lib/common_stuff.rb, line 66
def load_config
  file_conf = JSON.parse(File.read(@@config_file))
  cur_conf = fill_hash(file_conf['work_dir'], file_conf['batchy'], file_conf['auto_mater'])
  cur_conf
end
log_entry(printerdata, status) click to toggle source
# File lib/common_stuff.rb, line 12
def log_entry printerdata, status
  if File.exists?(@@prov_log)
    log_entry_write(printerdata, status)
  end
end
log_entry_data(printerdata, status) click to toggle source
# File lib/common_stuff.rb, line 24
def log_entry_data printerdata, status
  timey = Time.new
  case status
  when 0
    "Add: " + timey.inspect + " " + printerdata[0] + " " + printerdata[2] + " IP: " + printerdata[1]
  when 1
    "FAILED: " + timey.inspect + " " + printerdata[0] + " " + printerdata[2] + " IP: " + printerdata[1]
  end
end
log_entry_write(printerdata, status) click to toggle source
# File lib/common_stuff.rb, line 18
def log_entry_write printerdata, status
  File.open(@@prov_log, "a") do |f|
    f.puts log_entry_data(printerdata, status)
  end
end
log_file() click to toggle source
# File lib/common_stuff.rb, line 6
def log_file
  if Dir.exists?("/var/log/cups")
    File.new(@@prov_log, "w+") unless File.exists?(@@prov_log)
  end
end
mod_name(namey, store) click to toggle source
# File lib/common_stuff.rb, line 34
def mod_name namey, store
  namey = "0" + store + namey if namey.include?('RT') || namey.include?('SIM')
  namey
end
prompt() click to toggle source
# File lib/common_stuff.rb, line 39
def prompt
  print ">> "
end
save_config(cur_conf) click to toggle source
# File lib/common_stuff.rb, line 72
def save_config(cur_conf)
  File.open(@@config_file, "w") do |f|
    f.write(cur_conf.to_json)
  end
end
yes_no() click to toggle source
# File lib/common_stuff.rb, line 43
def yes_no
  #restrict input to valid answers, but don't worry about case
  begin
    puts "Please enter " + "[yes]".yellow + " or " + "[no]".yellow + ":"
    prompt; @yes_no = STDIN.gets.chomp.downcase
  end while not (@yes_no == "yes" or @yes_no == "no")
  @yes_no
end