Class: Smartware::Interface::Printer
- Inherits:
-
Smartware::Interface
- Object
- Smartware::Interface
- Smartware::Interface::Printer
- Defined in:
- lib/smartware/interfaces/printer.rb
Constant Summary collapse
- HARDWARE_ERROR =
1
- COMMUNICATION_ERROR =
2
- OUT_OF_PAPER =
3
- PAPER_NEAR_END =
1000
Instance Method Summary collapse
-
#initialize(config, service) ⇒ Printer
constructor
A new instance of Printer.
- #print(file, max_time = 30) ⇒ Object
- #print_markdown(text, max_time = 30) ⇒ Object
- #print_text(text, max_time = 30) ⇒ Object
- #test ⇒ Object
Constructor Details
#initialize(config, service) ⇒ Printer
Returns a new instance of Printer.
10 11 12 13 14 15 16 17 |
# File 'lib/smartware/interfaces/printer.rb', line 10 def initialize(config, service) super @printer_mutex = Mutex.new Thread.new &method(:poll) @render = @device.new_render @markdown = Redcarpet::Markdown.new(@render) end |
Instance Method Details
#print(file, max_time = 30) ⇒ Object
32 33 34 35 36 |
# File 'lib/smartware/interfaces/printer.rb', line 32 def print(file, max_time = 30) File.open(file, "r") do |io| print_markdown io.read, max_time end end |
#print_markdown(text, max_time = 30) ⇒ Object
38 39 40 |
# File 'lib/smartware/interfaces/printer.rb', line 38 def print_markdown(text, max_time = 30) do_print @markdown.render(text), max_time end |
#print_text(text, max_time = 30) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/smartware/interfaces/printer.rb', line 42 def print_text(text, max_time = 30) data = "".force_encoding("BINARY") data << @render.doc_header.force_encoding("BINARY") if @render.respond_to? :doc_header data << @render.normal_text(text, true).force_encoding("BINARY") if @render.respond_to? :normal_text data << @render.linebreak.force_encoding("BINARY") if @render.respond_to? :linebreak data << @render..force_encoding("BINARY") if @render.respond_to? :doc_footer do_print data, max_time end |