Module: Unicode::DisplayWidth

Defined in:
lib/unicode/display_width.rb

Constant Summary collapse

VERSION =
'0.3.1'.freeze
DATA_DIR =
File.join(File.dirname(__FILE__), '../../data/').freeze
TABLE_FILE =
(DATA_DIR + 'EastAsianWidth.index').freeze
DATA_FILE =
(DATA_DIR + 'EastAsianWidth.txt').freeze

Class Method Summary collapse

Class Method Details

.codepoint(n) ⇒ Object Also known as: width, of



19
20
21
22
# File 'lib/unicode/display_width.rb', line 19

def codepoint(n)
  n = n.to_s.unpack('U')[0] unless n.is_a? Integer
  table[n] or raise ArgumentError, 'codepoint not found'
end

.tableObject



11
12
13
14
15
16
17
# File 'lib/unicode/display_width.rb', line 11

def table
  if defined?(@table) && @table
    @table
  else
    @table = Marshal.load File.respond_to?(:binread) ? File.binread(TABLE_FILE) : File.read(TABLE_FILE)
  end
end