Class: UniProp::UnihanProp
- Inherits:
-
Object
- Object
- UniProp::UnihanProp
- Defined in:
- lib/uniprop/unihanprop.rb
Instance Attribute Summary collapse
-
#unihan_files ⇒ Object
readonly
Returns the value of attribute unihan_files.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(unihan_files) ⇒ UnihanProp
constructor
A new instance of UnihanProp.
- #property_name_to_shaped_lines ⇒ Hash<String,Array<String>>
-
#property_names ⇒ Set<String>
Unihanに含まれるプロパティ名を取得.
- #property_to_shaped_lines ⇒ Hash<Property,Array<String>>
-
#shaped_lines ⇒ Array<Array<String>>
unihan_filesに含まれるすべてのPropFileのshaped_linesを連結したオブジェクトを取得.
-
#unihan_properties ⇒ Set<Property>
Unihanに含まれるプロパティを取得.
- #unihan_value_group(property) ⇒ UnihanValueGroup
Constructor Details
#initialize(unihan_files) ⇒ UnihanProp
Returns a new instance of UnihanProp.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/uniprop/unihanprop.rb', line 6 def initialize(unihan_files) @unihan_files = unihan_files versions = @unihan_files.map { _1.version }.uniq if versions.size <= 1 @version = versions[0] else raise VersionDifferentError, "All versions of files in unihan_files should be the same." end end |
Instance Attribute Details
#unihan_files ⇒ Object (readonly)
Returns the value of attribute unihan_files.
3 4 5 |
# File 'lib/uniprop/unihanprop.rb', line 3 def unihan_files @unihan_files end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/uniprop/unihanprop.rb', line 3 def version @version end |
Instance Method Details
#property_name_to_shaped_lines ⇒ Hash<String,Array<String>>
56 57 58 59 60 61 |
# File 'lib/uniprop/unihanprop.rb', line 56 def property_name_to_shaped_lines return @property_nameto_shaped_lines if @property_name_to_shaped_lines @property_name_to_shaped_lines = shaped_lines.group_by { _1[1] } @property_name_to_shaped_lines.delete(nil) @property_name_to_shaped_lines end |
#property_names ⇒ Set<String>
Note:
Unihanのファイルは必ず2列目にプロパティ名が記述されている
Unihanに含まれるプロパティ名を取得
28 29 30 31 32 |
# File 'lib/uniprop/unihanprop.rb', line 28 def property_names @property_names ||= shaped_lines.map { _1[1] } .reject { !_1 } .to_set end |
#property_to_shaped_lines ⇒ Hash<Property,Array<String>>
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/uniprop/unihanprop.rb', line 64 def property_to_shaped_lines return @property_to_shaped_lines if @property_to_shaped_lines @property_to_shaped_lines = Hash.new property_name_to_shaped_lines.each do |property_name, lines| if version.has_unihan_property?(property_name) prop = version.find_unihan_property(property_name) @property_to_shaped_lines[prop] = lines end end @property_to_shaped_lines end |
#shaped_lines ⇒ Array<Array<String>>
unihan_filesに含まれるすべてのPropFileのshaped_linesを連結したオブジェクトを取得
19 20 21 22 23 |
# File 'lib/uniprop/unihanprop.rb', line 19 def shaped_lines @shaped_lines ||= unihan_files.map { _1.shaped_lines } .reject { _1.empty? || !_1 } .reduce([], :+) end |
#unihan_properties ⇒ Set<Property>
Unihanに含まれるプロパティを取得
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/uniprop/unihanprop.rb', line 36 def unihan_properties return @unihan_properties if @unihan_properties @unihan_properties = Set.new return if !version property_names.each do |property_name| if version.has_property?(property_name) # Unihanのプロパティの一部はPropertyAliases.txtにも記述されている # PropertyAliasesの方がプロパティのエイリアスなど、掲載されている情報が多いため、PropertyAliasesの記述を優先して使用 @unihan_properties << version.find_property(property_name) else @unihan_properties << UniProp::Property.new(version, property_name) end end @unihan_properties end |
#unihan_value_group(property) ⇒ UnihanValueGroup
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uniprop/unihanprop.rb', line 80 def unihan_value_group(property) return @property_to_unihan_value_group[property] if @property_to_unihan_value_group && @property_to_unihan_value_group[property] @property_to_unihan_value_group ||= {} unihan_value_group = UnihanValueGroup.new(property, property_to_shaped_lines[property]) @property_to_unihan_value_group[property] = unihan_value_group @property_to_unihan_value_group[property] end |