Module: Escpos::Helpers
Instance Method Summary collapse
- #barcode(data, opts = {}) ⇒ Object
- #black ⇒ Object (also: #default_color, #black_color, #color_black)
- #bold(data) ⇒ Object (also: #b)
- #center(data = '') ⇒ Object
- #cut ⇒ Object
- #double_height(data) ⇒ Object
- #double_width(data) ⇒ Object
-
#encode(data, opts = {}) ⇒ Object
Encodes UTF-8 string to encoding acceptable for the printer The printer must be set to that encoding Available encodings can be listed in console using Encoding.constants.
-
#encoding(data) ⇒ Object
(also: #set_encoding, #set_printer_encoding)
Set printer encoding example: encoding(Escpos::CP_ISO8859_2).
- #inverted(data) ⇒ Object (also: #invert)
- #left(data = '') ⇒ Object
- #partial_cut ⇒ Object
- #quad_text(data) ⇒ Object (also: #big, #title, #header, #double_width_double_height, #double_height_double_width)
- #red ⇒ Object (also: #alt_color, #alternative_color, #red_color, #color_red)
- #right(data = '') ⇒ Object
- #text(data) ⇒ Object
- #underline(data) ⇒ Object (also: #u)
- #underline2(data) ⇒ Object (also: #u2)
Instance Method Details
#barcode(data, opts = {}) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/escpos/helpers.rb', line 147 def (data, opts = {}) text_position = opts.fetch(:text_position, Escpos::BARCODE_TXT_OFF) possible_text_positions = [ Escpos::BARCODE_TXT_OFF, Escpos::BARCODE_TXT_ABV, Escpos::BARCODE_TXT_BLW, Escpos::BARCODE_TXT_BTH ] unless possible_text_positions.include?(text_position) raise ArgumentError("Wrong text position.") end height = opts.fetch(:height, 50) if height && (height < 1 || height > 255) raise ArgumentError("Height must be in range from 1 to 255.") end width = opts.fetch(:width, 3) if width && (width < 2 || width > 6) raise ArgumentError("Width must be in range from 2 to 6.") end [ Escpos.sequence(text_position), Escpos.sequence(Escpos::BARCODE_WIDTH), Escpos.sequence([width]), Escpos.sequence(Escpos::BARCODE_HEIGHT), Escpos.sequence([height]), Escpos.sequence(opts.fetch(:format, Escpos::BARCODE_EAN13)), data ].join end |
#black ⇒ Object Also known as: default_color, black_color, color_black
124 125 126 127 128 129 130 |
# File 'lib/escpos/helpers.rb', line 124 def black [ Escpos.sequence(Escpos::TXT_COLOR_BLACK), data, Escpos.sequence(Escpos::TXT_COLOR_BLACK), ].join end |
#bold(data) ⇒ Object Also known as: b
82 83 84 85 86 87 88 |
# File 'lib/escpos/helpers.rb', line 82 def bold(data) [ Escpos.sequence(Escpos::TXT_BOLD_ON), data, Escpos.sequence(Escpos::TXT_BOLD_OFF), ].join end |
#center(data = '') ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/escpos/helpers.rb', line 107 def center(data = '') [ Escpos.sequence(Escpos::TXT_ALIGN_CT), data, Escpos.sequence(Escpos::TXT_ALIGN_LT), ].join end |
#cut ⇒ Object
181 182 183 |
# File 'lib/escpos/helpers.rb', line 181 def cut Escpos.sequence(Escpos::PAPER_FULL_CUT) end |
#double_height(data) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/escpos/helpers.rb', line 35 def double_height(data) [ Escpos.sequence(Escpos::TXT_2HEIGHT), data, Escpos.sequence(Escpos::TXT_NORMAL), ].join end |
#double_width(data) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/escpos/helpers.rb', line 56 def double_width(data) [ Escpos.sequence(Escpos::TXT_2WIDTH), data, Escpos.sequence(Escpos::TXT_NORMAL), ].join end |
#encode(data, opts = {}) ⇒ Object
Encodes UTF-8 string to encoding acceptable for the printer The printer must be set to that encoding Available encodings can be listed in console using Encoding.constants
8 9 10 11 12 13 14 |
# File 'lib/escpos/helpers.rb', line 8 def encode(data, opts = {}) data.encode(opts.fetch(:encoding), 'UTF-8', { invalid: opts.fetch(:invalid, :replace), undef: opts.fetch(:undef, :replace), replace: opts.fetch(:replace, '?') }) end |
#encoding(data) ⇒ Object Also known as: set_encoding, set_printer_encoding
Set printer encoding example: encoding(Escpos::CP_ISO8859_2)
18 19 20 21 22 23 |
# File 'lib/escpos/helpers.rb', line 18 def encoding(data) [ Escpos.sequence(Escpos::CP_SET), Escpos.sequence(data) ].join end |
#inverted(data) ⇒ Object Also known as: invert
115 116 117 118 119 120 121 |
# File 'lib/escpos/helpers.rb', line 115 def inverted(data) [ Escpos.sequence(Escpos::TXT_INVERT_ON), data, Escpos.sequence(Escpos::TXT_INVERT_OFF), ].join end |
#left(data = '') ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/escpos/helpers.rb', line 91 def left(data = '') [ Escpos.sequence(Escpos::TXT_ALIGN_LT), data, Escpos.sequence(Escpos::TXT_ALIGN_LT), ].join end |
#partial_cut ⇒ Object
177 178 179 |
# File 'lib/escpos/helpers.rb', line 177 def partial_cut Escpos.sequence(Escpos::PAPER_PARTIAL_CUT) end |
#quad_text(data) ⇒ Object Also known as: big, title, header, double_width_double_height, double_height_double_width
43 44 45 46 47 48 49 |
# File 'lib/escpos/helpers.rb', line 43 def quad_text(data) [ Escpos.sequence(Escpos::TXT_4SQUARE), data, Escpos.sequence(Escpos::TXT_NORMAL), ].join end |
#red ⇒ Object Also known as: alt_color, alternative_color, red_color, color_red
135 136 137 138 139 140 141 |
# File 'lib/escpos/helpers.rb', line 135 def red [ Escpos.sequence(Escpos::TXT_COLOR_BLACK), data, Escpos.sequence(Escpos::TXT_COLOR_RED), ].join end |
#right(data = '') ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/escpos/helpers.rb', line 99 def right(data = '') [ Escpos.sequence(Escpos::TXT_ALIGN_RT), data, Escpos.sequence(Escpos::TXT_ALIGN_LT), ].join end |
#text(data) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/escpos/helpers.rb', line 27 def text(data) [ Escpos.sequence(Escpos::TXT_NORMAL), data, Escpos.sequence(Escpos::TXT_NORMAL), ].join end |
#underline(data) ⇒ Object Also known as: u
64 65 66 67 68 69 70 |
# File 'lib/escpos/helpers.rb', line 64 def underline(data) [ Escpos.sequence(Escpos::TXT_UNDERL_ON), data, Escpos.sequence(Escpos::TXT_UNDERL_OFF), ].join end |
#underline2(data) ⇒ Object Also known as: u2
73 74 75 76 77 78 79 |
# File 'lib/escpos/helpers.rb', line 73 def underline2(data) [ Escpos.sequence(Escpos::TXT_UNDERL2_ON), data, Escpos.sequence(Escpos::TXT_UNDERL_OFF), ].join end |