Class: Thermal::Db::Encoding

Inherits:
Object
  • Object
show all
Defined in:
lib/thermal/db/encoding.rb

Constant Summary collapse

RANGE =
(128..255)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#charmapObject (readonly)

Returns the value of attribute charmap.



8
9
10
# File 'lib/thermal/db/encoding.rb', line 8

def charmap
  @charmap
end

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

Returns:

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

Returns:

  • (Boolean)


26
27
28
# File 'lib/thermal/db/encoding.rb', line 26

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

#u_codepointsObject



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