Class: Rescpos::Printer
- Inherits:
-
Object
- Object
- Rescpos::Printer
- Defined in:
- lib/rescpos/printer.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(ip, port) ⇒ Printer
constructor
A new instance of Printer.
- #print(content, opts = {:encoding => 'GBK'}) ⇒ Object
- #print_report(report, opts = {}) ⇒ Object
Constructor Details
#initialize(ip, port) ⇒ Printer
Returns a new instance of Printer.
5 6 7 8 |
# File 'lib/rescpos/printer.rb', line 5 def initialize(ip, port) @socket = TCPSocket.open(ip, port) @socket.send("\x1b\x40", Socket::MSG_OOB) end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
3 4 5 |
# File 'lib/rescpos/printer.rb', line 3 def socket @socket end |
Class Method Details
.open(ip, port) ⇒ Object
10 11 12 |
# File 'lib/rescpos/printer.rb', line 10 def self.open(ip, port) printer = new(ip, port) end |
Instance Method Details
#close ⇒ Object
14 15 16 |
# File 'lib/rescpos/printer.rb', line 14 def close @socket.close end |
#print(content, opts = {:encoding => 'GBK'}) ⇒ Object
18 19 20 21 22 |
# File 'lib/rescpos/printer.rb', line 18 def print(content, opts={:encoding => 'GBK'}) content = Iconv.iconv("#{opts[:encoding]}//IGNORE","UTF-8//IGNORE", content)[0] @socket.send(content, Socket::MSG_OOB) cut end |
#print_report(report, opts = {}) ⇒ Object
24 25 26 |
# File 'lib/rescpos/printer.rb', line 24 def print_report(report, opts={}) print(report.render, opts) end |