Module: Unicode::SequenceName
- Defined in:
- lib/unicode/sequence_name.rb,
lib/unicode/sequence_name/index.rb,
lib/unicode/sequence_name/constants.rb
Constant Summary collapse
- VERSION =
"1.15.2"
- UNICODE_VERSION =
"16.0.0"
- EMOJI_VERSION =
"16.0"
- IVD_VERSION =
"2022-09-13"
- DATA_DIRECTORY =
File.(File.dirname(__FILE__) + "/../../../data/").freeze
- INDEX_FILENAME =
(DATA_DIRECTORY + "/sequence_name.marshal.gz").freeze
Class Method Summary collapse
- .fully_qualified(string) ⇒ Object
- .get_codepoint_values(string) ⇒ Object
- .insert_words(raw_name) ⇒ Object
- .sequence_name(string) ⇒ Object (also: of)
Class Method Details
.fully_qualified(string) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/unicode/sequence_name.rb', line 16 def self.fully_qualified(string) codepoints = get_codepoint_values(string) require_relative "sequence_name/index" unless defined? ::Unicode::SequenceName::INDEX if res = INDEX[:SEQUENCES][codepoints] insert_words(res) else nil end end |
.get_codepoint_values(string) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/unicode/sequence_name.rb', line 26 def self.get_codepoint_values(string) if string.valid_encoding? return string.codepoints elsif string.encoding.name == "UTF-8" begin return string.unpack("U*") rescue ArgumentError end end raise(ArgumentError, "Unicode::SequenceName.of must be given a valid string") end |
.insert_words(raw_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unicode/sequence_name.rb', line 39 def self.insert_words(raw_name) raw_name.chars.map{ |char| codepoint = char.ord if codepoint < INDEX[:REPLACE_BASE] char else "#{INDEX[:COMMON_WORDS][codepoint - INDEX[:REPLACE_BASE]]} " end }.join.chomp end |
.sequence_name(string) ⇒ Object Also known as: of
5 6 7 8 9 10 11 12 13 |
# File 'lib/unicode/sequence_name.rb', line 5 def self.sequence_name(string) codepoints = get_codepoint_values(string) require_relative "sequence_name/index" unless defined? ::Unicode::SequenceName::INDEX if res = INDEX[:SEQUENCES][codepoints] || INDEX[:SEQUENCES_NOT_QUALIFIED][codepoints] insert_words(res) else nil end end |