Class: Thermal::Db::Charset

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#charmapObject (readonly)

Returns the value of attribute charmap.



10
11
12
# File 'lib/thermal/db/charset.rb', line 10

def charmap
  @charmap
end

#keyObject (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

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/thermal/db/charset.rb', line 27

def codepoint?(u_codepoint)
  !!codepoints&.include?(u_codepoint)
end

#u_codepointsObject



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