Class: TwitterCldr::Shared::CodePoint

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#fieldsObject (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

.eachObject


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

.maxObject


161
162
163
# File 'lib/twitter_cldr/shared/code_point.rb', line 161

def max
  MAX_CODE_POINT
end

.propertiesObject


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_classObject


31
32
33
# File 'lib/twitter_cldr/shared/code_point.rb', line 31

def bidi_class
  @fields[4]
end

#bidi_mirroredObject


71
72
73
# File 'lib/twitter_cldr/shared/code_point.rb', line 71

def bidi_mirrored
  @fields[9]
end

#categoryObject


23
24
25
# File 'lib/twitter_cldr/shared/code_point.rb', line 23

def category
  @fields[2]
end

#code_pointObject


15
16
17
# File 'lib/twitter_cldr/shared/code_point.rb', line 15

def code_point
  @fields[0]
end

#combining_classObject


27
28
29
# File 'lib/twitter_cldr/shared/code_point.rb', line 27

def combining_class
  @fields[3]
end

#compatibility_decomposition_tagObject


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

#decompositionObject


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_valueObject


59
60
61
# File 'lib/twitter_cldr/shared/code_point.rb', line 59

def digit_value
  @fields[6]
end

#iso_commentObject


79
80
81
# File 'lib/twitter_cldr/shared/code_point.rb', line 79

def iso_comment
  @fields[11]
end

#nameObject


19
20
21
# File 'lib/twitter_cldr/shared/code_point.rb', line 19

def name
  @fields[1]
end

#non_decimal_digit_valueObject


63
64
65
# File 'lib/twitter_cldr/shared/code_point.rb', line 63

def non_decimal_digit_value
  @fields[7]
end

#numeric_valueObject


67
68
69
# File 'lib/twitter_cldr/shared/code_point.rb', line 67

def numeric_value
  @fields[8]
end

#propertiesObject


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_mapObject


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_mapObject


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_mapObject


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_nameObject


75
76
77
# File 'lib/twitter_cldr/shared/code_point.rb', line 75

def unicode1_name
  @fields[10]
end