UnicodeData#for_code_point returns a Struct instead of an Array. #19

Merged
merged 6 commits into from Apr 30, 2012
@@ -27,11 +27,11 @@ def normalize_code_points(code_points)
def decompose(code_point)
unicode_data = TwitterCldr::Shared::UnicodeData.for_code_point(code_point)
return code_point unless unicode_data
- decomposition_mapping = unicode_data[5].split
+ decomposition_mapping = unicode_data.decomposition.split
# Special decomposition for Hangul syllables.
# Documented in Section 3.12 at http://www.unicode.org/versions/Unicode6.1.0/ch03.pdf
- if unicode_data[1].include? 'Hangul'
+ if unicode_data.name.include? 'Hangul'
sIndex = code_point.hex - @@hangul_constants[:SBase]
lIndex = sIndex / @@hangul_constants[:NCount]
@@ -70,7 +70,7 @@ def reorder(code_points)
def combining_class_for(code_point)
begin
- unicode_data = TwitterCldr::Shared::UnicodeData.for_code_point(code_point)[3].to_i
+ unicode_data = TwitterCldr::Shared::UnicodeData.for_code_point(code_point).combining_class.to_i
rescue NoMethodError
0
end
@@ -6,6 +6,9 @@
module TwitterCldr
module Shared
class UnicodeData
+ Attributes = Struct.new(:code_point, :name, :category, :combining_class, :bidi_class, :decomposition,
+ :digit_value, :non_decimal_digit_value, :numeric_value, :bidi_mirrored, :unicode1_name,
+ :iso_comment, :simple_uppercase_map, :simple_lowercase_map, :simple_titlecase_map)
class << self
def for_code_point(code_point)
blocks = TwitterCldr.get_resource("unicode_data", "blocks")
@@ -17,7 +20,8 @@ def for_code_point(code_point)
if target
block_data = TwitterCldr.get_resource("unicode_data", target.first)
- block_data.fetch(code_point.to_sym) { |code_point_sym| get_range_start(code_point_sym, block_data) }
+ code_point_data = block_data.fetch(code_point.to_sym) { |code_point_sym| get_range_start(code_point_sym, block_data) }
+ Attributes.new(*code_point_data) if code_point_data
end
end
@@ -11,7 +11,7 @@
describe "#for_code_point" do
it "should retrieve information for any valid code point" do
data = UnicodeData.for_code_point('0301')
- data.should be_a(Array)
+ data.should be_a(Struct)
data.length.should == 15
end
@@ -29,9 +29,8 @@
'2128' => ['2128','BLACK-LETTER CAPITAL Z','Lu','0','L','<font> 005A',"","","",'N','BLACK-LETTER Z',"","","",""],
'1F241'=> ['1F241','TORTOISE SHELL BRACKETED CJK UNIFIED IDEOGRAPH-4E09','So','0','L','<compat> 3014 4E09 3015',"","","",'N',"","","","",""]
}
-
test_data.each_pair do |code_point, data|
- UnicodeData.for_code_point(code_point).should == data
+ UnicodeData.for_code_point(code_point).values.should == data
end
end
@@ -45,7 +44,7 @@
}
test_data.each_pair do |code_point, data|
- UnicodeData.for_code_point(code_point).should == data
+ UnicodeData.for_code_point(code_point).values.should == data
end
end
end