Class: Sapos::Print::QReader
- Inherits:
-
Object
- Object
- Sapos::Print::QReader
- Defined in:
- lib/sapos/print/q_reader.rb
Class Attribute Summary collapse
-
.printer_config ⇒ Object
Returns the value of attribute printer_config.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#printers ⇒ Object
Returns the value of attribute printers.
-
#pubnub ⇒ Object
Returns the value of attribute pubnub.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ QReader
constructor
A new instance of QReader.
Constructor Details
#initialize ⇒ QReader
Returns a new instance of QReader.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sapos/print/q_reader.rb', line 60 def initialize @config = QReader.printer_config @printer = Printer.new(@config) @printers = {} @config.printers.each_with_index do |printer, idx| config = @config.dup config.printer = printer config.interface = @config.interfaces[idx] @printers[printer] = Printer.new(config) end @pubnub = Pubnub.new(subscribe_key: @config.key, user_id: @config.user_id, ssl: true) end |
Class Attribute Details
.printer_config ⇒ Object
Returns the value of attribute printer_config.
7 8 9 |
# File 'lib/sapos/print/q_reader.rb', line 7 def printer_config @printer_config end |
.verbose ⇒ Object
Returns the value of attribute verbose.
7 8 9 |
# File 'lib/sapos/print/q_reader.rb', line 7 def verbose @verbose end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/sapos/print/q_reader.rb', line 10 def config @config end |
#printer ⇒ Object
Returns the value of attribute printer.
10 11 12 |
# File 'lib/sapos/print/q_reader.rb', line 10 def printer @printer end |
#printers ⇒ Object
Returns the value of attribute printers.
10 11 12 |
# File 'lib/sapos/print/q_reader.rb', line 10 def printers @printers end |
#pubnub ⇒ Object
Returns the value of attribute pubnub.
10 11 12 |
# File 'lib/sapos/print/q_reader.rb', line 10 def pubnub @pubnub end |
Class Method Details
.run! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sapos/print/q_reader.rb', line 12 def self.run! reader = QReader.new callback = Pubnub::SubscribeCallback.new( message: -> (envelope){ begin msg = envelope.result[:data][:message] msgid = envelope.result.dig(:data, :publish_time_object, :timetoken) print_control = nil document_number = nil puts msg.inspect if reader.config.verbose printer_name = nil if msg.is_a?(Hash) print_control = msg['print_control'] document_number = msg['document_number'] printer_name = msg["printer"] msg = msg['document'] end document = Base64.decode64(msg) current_printer = reader.printer if printer_name && reader.printers[printer_name] current_printer = reader.printers[printer_name] end puts "Printer Config: #{current_printer.to_h}" if reader.config.verbose if !current_printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid, printer: printer_name) puts "Printer Error" end rescue => e puts "Error: #{e.}" end }, presence: ->(envelope){}, status: ->(envelope){} ) reader.pubnub.add_listener(callback: callback) reader.pubnub.subscribe(channels: [reader.config.q]) ARGV.clear while line = gets do #Wait forever ;-) end end |