Module: CommonStuff
- Defined in:
- lib/common_stuff.rb
Constant Summary collapse
- @@config_file =
File.join(Dir.home, "printsly.json")
- @@prov_log =
"/var/log/cups/provision_log"
Instance Method Summary collapse
- #choose_file ⇒ Object
- #fill_hash(work_dir, batchy, auto_mater) ⇒ Object
- #load_config ⇒ Object
- #log_entry(printerdata, status) ⇒ Object
- #log_entry_data(printerdata, status) ⇒ Object
- #log_entry_write(printerdata, status) ⇒ Object
- #log_file ⇒ Object
- #mod_name(namey, store) ⇒ Object
- #prompt ⇒ Object
- #save_config(cur_conf) ⇒ Object
- #yes_no ⇒ Object
Instance Method Details
#choose_file ⇒ Object
52 53 54 55 56 |
# 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) ⇒ Object
58 59 60 61 62 63 64 |
# 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 ⇒ Object
66 67 68 69 70 |
# 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) ⇒ Object
12 13 14 15 16 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
18 19 20 21 22 |
# 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 ⇒ Object
6 7 8 9 10 |
# 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) ⇒ Object
34 35 36 37 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/common_stuff.rb', line 39 def prompt print ">> " end |
#save_config(cur_conf) ⇒ Object
72 73 74 75 76 |
# 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 ⇒ Object
43 44 45 46 47 48 49 50 |
# 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 |