Class: Thermal::Db::CjkEncoding

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

Overview

Adds CJK character encoding lookup.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, ruby) ⇒ CjkEncoding

Returns a new instance of CjkEncoding.



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

def initialize(key, ruby)
  @key = key
  @ruby = ruby
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/thermal/db/cjk_encoding.rb', line 7

def key
  @key
end

#rubyObject (readonly)

Returns the value of attribute ruby.



7
8
9
# File 'lib/thermal/db/cjk_encoding.rb', line 7

def ruby
  @ruby
end

Instance Method Details

#char(u_char) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/thermal/db/cjk_encoding.rb', line 24

def char(u_char)
  return if u_char.ord <= 127

  char = u_char.encode(@ruby)
  char unless skip?(char)
rescue EncodingError
  nil
end

#char?(u_char) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/thermal/db/cjk_encoding.rb', line 33

def char?(u_char)
  !!char(u_char)
end

#codepoint(u_codepoint) ⇒ Object



14
15
16
17
18
# File 'lib/thermal/db/cjk_encoding.rb', line 14

def codepoint(u_codepoint)
  char(u_codepoint.chr('UTF-8'))
rescue RangeError
  nil
end

#codepoint?(u_codepoint) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/thermal/db/cjk_encoding.rb', line 20

def codepoint?(u_codepoint)
  !!codepoint(u_codepoint)
end