class TwitterCldr::Shared::CodePoint
Constants
- DECOMPOSITION_REGEX
- MAX_CODE_POINT
Attributes
fields[R]
Public Class Methods
new(fields)
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 101 def initialize(fields) @fields = fields end
Private Class Methods
block_cache()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 177 def block_cache @block_cache ||= {} end
blocks()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 181 def blocks @blocks ||= TwitterCldr.get_resource( :unicode_data, :blocks ) end
code_point_cache()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 167 def code_point_cache @code_point_cache ||= {} end
code_points_for_property(property_name, property_value = nil)
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 139 def code_points_for_property(property_name, property_value = nil) properties.code_points_for_property( property_name, property_value ) end
each() { |found_cp| ... }
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 149 def each if block_given? (0..max).each do |cp| if found_cp = get(cp) yield found_cp end end else to_enum(__method__) end end
get(code_point)
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 122 def get(code_point) code_point_cache[code_point] ||= begin target = get_block(code_point) return unless target && target.first block_data = TwitterCldr.get_resource(:unicode_data, :blocks, target.first) code_point_data = block_data.fetch(code_point) { |cp| get_range_start(cp, block_data) } CodePoint.new(code_point_data) if code_point_data end end
get_block(code_point)
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 171 def get_block(code_point) block_cache[code_point] ||= blocks.detect do |_, range| range.include?(code_point) end end
get_range_start(code_point, block_data)
click to toggle source
Check if block constitutes a range. The code point beginning a range will have a name enclosed in <>, ending with 'First' eg: <CJK Ideograph Extension A, First> unicode.org/reports/tr44/#Code_Point_Ranges
# File lib/twitter_cldr/shared/code_point.rb, line 190 def get_range_start(code_point, block_data) start_data = block_data[block_data.keys.min] if start_data[1] =~ /<.*, First>/ start_data = start_data.clone start_data[0] = code_point start_data[1] = start_data[1].sub(', First', '') start_data end end
max()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 161 def max MAX_CODE_POINT end
properties()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 135 def properties @properties ||= TwitterCldr::Shared::PropertiesDatabase.new end
properties_for_code_point(code_point)
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 145 def properties_for_code_point(code_point) properties.properties_for_code_point(code_point) end
Public Instance Methods
bidi_class()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 31 def bidi_class @fields[4] end
bidi_mirrored()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 71 def bidi_mirrored @fields[9] end
category()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 23 def category @fields[2] end
code_point()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 15 def code_point @fields[0] end
combining_class()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 27 def combining_class @fields[3] end
compatibility_decomposition_tag()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 47 def compatibility_decomposition_tag @compat_decomp_tag ||= begin decomp = fields[5] if decomp =~ DECOMPOSITION_REGEX $1 else raise ArgumentError, "decomposition #{decomp.inspect} has invalid format" end end end
decomposition()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 35 def decomposition @decomposition ||= begin decomp = fields[5] if decomp =~ DECOMPOSITION_REGEX $2 && $2.split.map(&:hex) else raise ArgumentError, "decomposition #{decomp.inspect} has invalid format" end end end
digit_value()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 59 def digit_value @fields[6] end
iso_comment()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 79 def iso_comment @fields[11] end
name()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 19 def name @fields[1] end
non_decimal_digit_value()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 63 def non_decimal_digit_value @fields[7] end
numeric_value()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 67 def numeric_value @fields[8] end
properties()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 105 def properties self.class.properties.properties_for_code_point(code_point) end
simple_lowercase_map()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 89 def simple_lowercase_map @lowercase ||= field_or_nil(13) do |val| [val.to_i(16)].pack('U*') end end
simple_titlecase_map()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 95 def simple_titlecase_map @titlecase ||= field_or_nil(14) do |val| [val.to_i(16)].pack('U*') end end
simple_uppercase_map()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 83 def simple_uppercase_map @uppercase ||= field_or_nil(12) do |val| [val.to_i(16)].pack('U*') end end
unicode1_name()
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 75 def unicode1_name @fields[10] end
Private Instance Methods
field_or_nil(index) { |val| ... }
click to toggle source
# File lib/twitter_cldr/shared/code_point.rb, line 111 def field_or_nil(index) val = @fields[index] if val && !val.empty? yield val end end