Class: TwitterCldr::Shared::CodePoint
- Inherits:
-
Object
- Object
- TwitterCldr::Shared::CodePoint
- Extended by:
- Enumerable
- Defined in:
- lib/twitter_cldr/shared/code_point.rb
Constant Summary collapse
- DECOMPOSITION_REGEX =
/^(?:<(.+)>\s+)?(.+)?$/
- MAX_CODE_POINT =
1_112_111
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
- .code_points_for_property(property_name, property_value = nil) ⇒ Object
- .each ⇒ Object
- .get(code_point) ⇒ Object
- .max ⇒ Object
- .properties ⇒ Object
- .properties_for_code_point(code_point) ⇒ Object
Instance Method Summary collapse
- #bidi_class ⇒ Object
- #bidi_mirrored ⇒ Object
- #category ⇒ Object
- #code_point ⇒ Object
- #combining_class ⇒ Object
- #compatibility_decomposition_tag ⇒ Object
- #decomposition ⇒ Object
- #digit_value ⇒ Object
-
#initialize(fields) ⇒ CodePoint
constructor
A new instance of CodePoint.
- #iso_comment ⇒ Object
- #name ⇒ Object
- #non_decimal_digit_value ⇒ Object
- #numeric_value ⇒ Object
- #properties ⇒ Object
- #simple_lowercase_map ⇒ Object
- #simple_titlecase_map ⇒ Object
- #simple_uppercase_map ⇒ Object
- #unicode1_name ⇒ Object
Constructor Details
#initialize(fields) ⇒ CodePoint
Returns a new instance of CodePoint.
101 102 103 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 101 def initialize(fields) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
13 14 15 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 13 def fields @fields end |
Class Method Details
.code_points_for_property(property_name, property_value = nil) ⇒ Object
139 140 141 142 143 |
# 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 ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# 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) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 |
.max ⇒ Object
161 162 163 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 161 def max MAX_CODE_POINT end |
.properties ⇒ Object
135 136 137 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 135 def properties @properties ||= TwitterCldr::Shared::PropertiesDatabase.new end |
.properties_for_code_point(code_point) ⇒ Object
145 146 147 |
# 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 |
Instance Method Details
#bidi_class ⇒ Object
31 32 33 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 31 def bidi_class @fields[4] end |
#bidi_mirrored ⇒ Object
71 72 73 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 71 def bidi_mirrored @fields[9] end |
#category ⇒ Object
23 24 25 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 23 def category @fields[2] end |
#code_point ⇒ Object
15 16 17 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 15 def code_point @fields[0] end |
#combining_class ⇒ Object
27 28 29 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 27 def combining_class @fields[3] end |
#compatibility_decomposition_tag ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# 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 ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 59 def digit_value @fields[6] end |
#iso_comment ⇒ Object
79 80 81 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 79 def iso_comment @fields[11] end |
#name ⇒ Object
19 20 21 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 19 def name @fields[1] end |
#non_decimal_digit_value ⇒ Object
63 64 65 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 63 def non_decimal_digit_value @fields[7] end |
#numeric_value ⇒ Object
67 68 69 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 67 def numeric_value @fields[8] end |
#properties ⇒ Object
105 106 107 |
# 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 ⇒ Object
89 90 91 92 93 |
# 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 ⇒ Object
95 96 97 98 99 |
# 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 ⇒ Object
83 84 85 86 87 |
# 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 ⇒ Object
75 76 77 |
# File 'lib/twitter_cldr/shared/code_point.rb', line 75 def unicode1_name @fields[10] end |