Class: Rescpos::Printer
- Inherits:
-
Object
- Object
- Rescpos::Printer
- Defined in:
- lib/rescpos/printer.rb
Constant Summary collapse
- SOCK_FLAG =
0
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', :cut_mode => :partial_cut }) ⇒ Object
- #print_report(report, opts = {}) ⇒ Object
Constructor Details
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
11 12 13 |
# File 'lib/rescpos/printer.rb', line 11 def self.open(ip, port) printer = new(ip, port) end |
Instance Method Details
#close ⇒ Object
15 16 17 |
# File 'lib/rescpos/printer.rb', line 15 def close @socket.close end |
#print(content, opts = { :encoding => 'GBK', :cut_mode => :partial_cut }) ⇒ Object
19 20 21 22 23 |
# File 'lib/rescpos/printer.rb', line 19 def print(content, opts = { :encoding => 'GBK', :cut_mode => :partial_cut }) content = Iconv.iconv("#{ opts[:encoding] || 'GBK' }//IGNORE","UTF-8//IGNORE", content)[0] @socket.send(content, SOCK_FLAG) send(opts[:cut_mode] || :partial_cut) end |
#print_report(report, opts = {}) ⇒ Object
25 26 27 |
# File 'lib/rescpos/printer.rb', line 25 def print_report(report, opts={}) print(report.render, opts) end |