Class: Thermal::Db::Charset
- Inherits:
-
Object
- Object
- Thermal::Db::Charset
- Defined in:
- lib/thermal/db/charset.rb
Overview
The charset is different than the codepage. It controls usage of specific ASCII-range code points such as dollar-sign ($).
Constant Summary collapse
- CODEPOINTS =
[0x23, 0x24, 0x25, 0x2A, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x60, 0x7B, 0x7C, 0x7D, 0x7E].freeze
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) ⇒ Charset
constructor
A new instance of Charset.
- #u_codepoints ⇒ Object
Constructor Details
#initialize(key, charmap) ⇒ Charset
Returns a new instance of Charset.
12 13 14 15 |
# File 'lib/thermal/db/charset.rb', line 12 def initialize(key, charmap) @key = key @charmap = Array(charmap)&.join&.freeze end |
Instance Attribute Details
#charmap ⇒ Object (readonly)
Returns the value of attribute charmap.
10 11 12 |
# File 'lib/thermal/db/charset.rb', line 10 def charmap @charmap end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/thermal/db/charset.rb', line 10 def key @key end |
Instance Method Details
#char?(char) ⇒ Boolean
23 24 25 |
# File 'lib/thermal/db/charset.rb', line 23 def char?(char) !!charmap&.include?(char) end |
#codepoint(u_codepoint) ⇒ Object
31 32 33 |
# File 'lib/thermal/db/charset.rb', line 31 def codepoint(u_codepoint) CODEPOINTS[u_codepoints&.index(u_codepoint)] end |
#codepoint?(u_codepoint) ⇒ Boolean
27 28 29 |
# File 'lib/thermal/db/charset.rb', line 27 def codepoint?(u_codepoint) !!codepoints&.include?(u_codepoint) end |
#u_codepoints ⇒ Object
17 18 19 20 21 |
# File 'lib/thermal/db/charset.rb', line 17 def u_codepoints return @u_codepoints if defined?(@u_codepoints) @u_codepoints = @charmap.each_codepoint.to_a end |