Class: Thermal::Db::Device
- Inherits:
-
Object
- Object
- Thermal::Db::Device
- Defined in:
- lib/thermal/db/device.rb
Constant Summary collapse
- DEFAULT_COL_WIDTH =
42
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #charsets ⇒ Object
-
#codepages ⇒ Object
def find_codepage(encoding) encoding = encoding&.to_s device.codepages&.invert&.[](encoding) || 0 end.
-
#col_width ⇒ Object
TODO: this needs to be dynamic in the printer.
- #find_encoding(u_codepoint) ⇒ Object
- #format ⇒ Object
-
#initialize(key, data) ⇒ Device
constructor
A new instance of Device.
- #name ⇒ Object
- #supports?(feature) ⇒ Boolean
Constructor Details
#initialize(key, data) ⇒ Device
Returns a new instance of Device.
10 11 12 13 14 15 16 17 |
# File 'lib/thermal/db/device.rb', line 10 def initialize(key, data) @key = key @data = data # eager load cache codepage_index charset_index end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/thermal/db/device.rb', line 8 def key @key end |
Instance Method Details
#charsets ⇒ Object
59 60 61 62 63 64 |
# File 'lib/thermal/db/device.rb', line 59 def charsets @charsets ||= begin charsets = @data['charsets'] || ::Thermal::Db::DEFAULT_CHARSETS ::Thermal::Util.index_with(charsets) { |i| ::Thermal::Db.charset(i) }.freeze end end |
#codepages ⇒ Object
def find_codepage(encoding)
encoding = encoding&.to_s
device.codepages&.invert&.[](encoding) || 0
end
49 50 51 52 53 54 55 56 57 |
# File 'lib/thermal/db/device.rb', line 49 def codepages @codepages ||= begin codepages = @data['codepages'] || ::Thermal::Db::DEFAULT_CODEPAGES codepages.each_with_object({}) do |(k, v), h| encoding = ::Thermal::Db.encoding(v) h[k] = encoding if encoding end.freeze end end |
#col_width ⇒ Object
TODO: this needs to be dynamic in the printer
32 33 34 |
# File 'lib/thermal/db/device.rb', line 32 def col_width @col_width ||= @data.dig('fonts', 0, 'columns') || DEFAULT_COL_WIDTH end |
#find_encoding(u_codepoint) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/thermal/db/device.rb', line 36 def find_encoding(u_codepoint) if (codepage = codepage_index[u_codepoint]) [:codepage, codepage].freeze elsif (charset = charset_index[u_codepoint]) && charset > 0 [:charset, charset].freeze end end |
#format ⇒ Object
23 24 25 |
# File 'lib/thermal/db/device.rb', line 23 def format @data['format']&.to_s end |
#name ⇒ Object
19 20 21 |
# File 'lib/thermal/db/device.rb', line 19 def name @data['name']&.to_s end |
#supports?(feature) ⇒ Boolean
27 28 29 |
# File 'lib/thermal/db/device.rb', line 27 def supports?(feature) !!@data.dig('features', feature) end |