Module: Unicode::Blocks

Defined in:
lib/unicode/blocks.rb,
lib/unicode/blocks/index.rb,
lib/unicode/blocks/constants.rb

Constant Summary collapse

VERSION =
"1.10.0"
UNICODE_VERSION =
"16.0.0"
DATA_DIRECTORY =
File.expand_path(File.dirname(__FILE__) + "/../../../data/").freeze
INDEX_FILENAME =
(DATA_DIRECTORY + "/blocks.marshal.gz").freeze

Class Method Summary collapse

Class Method Details

.block(char) ⇒ Object



15
16
17
18
19
20
# File 'lib/unicode/blocks.rb', line 15

def self.block(char)
  require_relative 'blocks/index' unless defined? ::Unicode::Blocks::INDEX
  codepoint = char.unpack("U")[0] or raise(ArgumentError, "Unicode::Blocks.block must be given a valid char")
  block_info = INDEX.bsearch{ |block_info| codepoint <= block_info[1] }
  codepoint >= block_info[0] ? block_info[2] : "No_Block"
end

.blocks(string) ⇒ Object Also known as: of



5
6
7
8
9
10
11
12
# File 'lib/unicode/blocks.rb', line 5

def self.blocks(string)
  res = []
  string.each_char{ |char|
    block_name = block(char)
    res << block_name unless res.include?(block_name)
  }
  res.sort
end

.namesObject



22
23
24
25
# File 'lib/unicode/blocks.rb', line 22

def self.names
  require_relative 'blocks/index' unless defined? ::Unicode::Blocks::INDEX
  INDEX.map(&:last)
end