Class: Thermal::Db::Encoding
- Inherits:
-
Object
- Object
- Thermal::Db::Encoding
- Defined in:
- lib/thermal/db/encoding.rb
Constant Summary collapse
- RANGE =
(128..255)
Instance Attribute Summary collapse
-
#charmap ⇒ Object
readonly
Returns the value of attribute charmap.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #char?(char) ⇒ Boolean
- #codepoint(u_codepoint) ⇒ Object
- #codepoint?(u_codepoint) ⇒ Boolean
-
#initialize(key, charmap) ⇒ Encoding
constructor
A new instance of Encoding.
- #u_codepoints ⇒ Object
Constructor Details
#initialize(key, charmap) ⇒ Encoding
Returns a new instance of Encoding.
10 11 12 13 14 |
# File 'lib/thermal/db/encoding.rb', line 10 def initialize(key, charmap) @key = key @charmap = Array(charmap)&.join&.freeze raise 'Invalid charmap' unless @charmap.size == 128 end |
Instance Attribute Details
#charmap ⇒ Object (readonly)
Returns the value of attribute charmap.
8 9 10 |
# File 'lib/thermal/db/encoding.rb', line 8 def charmap @charmap end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/thermal/db/encoding.rb', line 8 def key @key end |
Instance Method Details
#char?(char) ⇒ Boolean
22 23 24 |
# File 'lib/thermal/db/encoding.rb', line 22 def char?(char) !!charmap&.include?(char) end |
#codepoint(u_codepoint) ⇒ Object
30 31 32 |
# File 'lib/thermal/db/encoding.rb', line 30 def codepoint(u_codepoint) u_codepoints&.index(u_codepoint)&.+(128) end |
#codepoint?(u_codepoint) ⇒ Boolean
26 27 28 |
# File 'lib/thermal/db/encoding.rb', line 26 def codepoint?(u_codepoint) !!u_codepoints&.include?(u_codepoint) end |
#u_codepoints ⇒ Object
16 17 18 19 20 |
# File 'lib/thermal/db/encoding.rb', line 16 def u_codepoints return @u_codepoints if defined?(@u_codepoints) @u_codepoints = charmap.each_codepoint.to_a end |