Class: Printers

Inherits:
Object
  • Object
show all
Defined in:
lib/printers.rb

Instance Method Summary collapse

Constructor Details

#initializePrinters

Returns a new instance of Printers.



13
14
15
# File 'lib/printers.rb', line 13

def initialize

end

Instance Method Details

#batch(spread) ⇒ Object

attr_accessor :store_printers



4
5
6
7
8
9
10
11
# File 'lib/printers.rb', line 4

def batch spread
  book = Spreadsheet.open spread
  sheet1 = book.worksheet 0
  store = sheet1.row(0)[0][6..8]
  printers = hashy(sheet1, store)
  provision(printers, store)
  printers
end

#hashy(sheet, store) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/printers.rb', line 17

def hashy sheet, store
  store_printers = Hash.new
  sheet.each 5 do |row|
    break if row[0].nil?
    printername = row[4]
    if printername != nil
      store_printers[printername] = printer(row, printername, store)
    end
  end
  store_printers
end

#printer(row, printername, store) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/printers.rb', line 39

def printer row, printername, store
  if printername.include?(store) || printername.include?('RT') || printername.include?('SIM')
    printer = Array.new
    printer = printer.push row[4] # name
    printer = printer.push row[5] # ip address
    printer = printer.push row[3] # Model
    printer = printer.push row[0] # Description
    printer
  end
end

#provision(printers, store) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/printers.rb', line 50

def provision printers, store
  log_file
  $green = true
  printers.each do | printername, printerdata |
    printerdata[0] = mod_name(printerdata[0], store)
    lp_command = lpadmin_puts(printerdata)
    system "bash", "-c", lp_command
    if $?.exitstatus > 0
      puts "I failed to add #{printerdata[0]}!" # for CLI output
      $green = false
      log_entry(printerdata, 1)
    else
      log_entry(printerdata, 0)
    end
  end
end

#show_printers(printers, store) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/printers.rb', line 29

def show_printers printers, store
  puts
  puts prov_text(store)
  puts
  printers.each do | printername, printerdata |
    printerdata[0] = mod_name(printerdata[0], store)
    puts printer_puts(printerdata)
  end
end