module Forkforge::Unicode
Public Instance Methods
camel_to_underscore(s, constant = false)
click to toggle source
# File lib/forkforge/unicode.rb, line 24 def camel_to_underscore s, constant = false result = s.gsub(/(?<!\A)./) { |m| Letter::is_uppercase(m) ? "_#{m}" : m } constant ? uppercase(result) : lowercase(result) end
compose(s, tag = :font, format = :full)
click to toggle source
As an opposite to decomposition: composes symbols using given string and tag (when possible). This function is not intended to be used directly. Normally one uses one of aliases:
- circle - super - sub - wide
NB This is not a composition as it is understood by Unicode
.Org (love them.)
# File lib/forkforge/unicode.rb, line 51 def compose s, tag = :font, format = :full composed = s.codepoints.map { |cp| (result = Forkforge::UnicodeData::compose_cp(cp, tag, format == :full)).vacant? ? \ [Forkforge::UnicodeData::to_codepoint(cp)] : result } raise UnicodeException, "AMBIGUITIES FOUND, FIXME FIXME FIXME" \ if format == :lazy && (composed.length != s.length) case format when :full then Hash[s.split('').map.with_index { |ch, idx| [[ch,idx], composed[idx]] }] when :lazy then composed.join when :risk then composed.map(&:first).join else composed end end
decompose(s, tags = [])
click to toggle source
Decomposes symbols to their combined representation, e.g. ASCII c-cedilla to 2 symbols
# File lib/forkforge/unicode.rb, line 81 def decompose s, tags = [] s.codepoints.map { |cp| Forkforge::UnicodeData::decompose_cp cp, tags }.flatten.map { |cp| cp.to_i(16) }.pack('U*') end
fraktur(s)
click to toggle source
# File lib/forkforge/unicode.rb, line 74 def fraktur s s.split('').map do |c| Forkforge::UnicodeData::code_points.send(:math_fraktur_bold, c).to_s end.join end
lookup(pattern)
click to toggle source
# File lib/forkforge/unicode.rb, line 37 def lookup pattern Forkforge::UnicodeData::all_character_name(pattern).map { |k, v| Forkforge::UnicodeData::to_char k } end
underscore_to_camel(s)
click to toggle source
# File lib/forkforge/unicode.rb, line 31 def underscore_to_camel s (lowercase s).gsub(/((?<=\A)|_)(\w)/) { titlecase $~[2] } end