Class: UniProp::VersionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/uniprop/inspects.rb,
lib/uniprop/unicode_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ VersionManager

versionに含まれる情報を取得するためのオブジェクトを作成



113
114
115
# File 'lib/uniprop/unicode_manager.rb', line 113

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



109
110
111
# File 'lib/uniprop/unicode_manager.rb', line 109

def version
  @version
end

Instance Method Details

#assigned_codepoints(property) ⇒ Array<Integer>

propertyにデフォルト値以外の値が割り当てられているコードポイントを取得



178
179
180
# File 'lib/uniprop/unicode_manager.rb', line 178

def assigned_codepoints(property)
  property_manager(property).property_value_group.codepoints
end

#codepoints_of(property, value) ⇒ Array<Integer>

propertyプロパティが値としてvalueを持つコードポイントを取得



142
143
144
# File 'lib/uniprop/unicode_manager.rb', line 142

def codepoints_of(property, value)
  property_manager(property).property_value_group.value_including_codepoints(value)
end

#has_property?(property) ⇒ Boolean

propertyをエイリアスに持つプロパティがバージョン内に存在するか確認



171
172
173
# File 'lib/uniprop/unicode_manager.rb', line 171

def has_property?(property)
  version.has_property?(property)
end

#has_value?(property, codepoint, value) ⇒ Boolean

propertyがcodepointでプロパティ値としてvalueを持つか判定



150
151
152
# File 'lib/uniprop/unicode_manager.rb', line 150

def has_value?(property, codepoint, value)
  codepoints_of(property, value).include?(codepoint)
end

#inspectObject



117
118
119
# File 'lib/uniprop/inspects.rb', line 117

def inspect
  "#<#{self.class.name} #{version.version_name}>"
end

#propertiesArray<String>

バージョン内の全プロパティ名を取得



164
165
166
167
# File 'lib/uniprop/unicode_manager.rb', line 164

def properties
  # VersionMetaData#property_namesにはUniHanのプロパティが含まれないため、EffcientVersion#propertiesから取得

  @properties ||= version.properties.map { _1.longest_alias }
end

#properties_of(char, value) ⇒ Array<String>

codepointでvalueを取るプロパティを取得



158
159
160
# File 'lib/uniprop/unicode_manager.rb', line 158

def properties_of(char, value)
  properties.filter { has_value?(_1, char.ord, value) }
end

#property_manager(property_name) ⇒ PropertyManager

PropertyManagerオブジェクトを作成



120
121
122
123
124
125
126
127
128
# File 'lib/uniprop/unicode_manager.rb', line 120

def property_manager(property_name)
  @property_managers ||= []
  pm = @property_managers.find { _1.property.has_alias?(property_name) }
  return pm if pm

  pm = PropertyManager.new(version.find_property(property_name))
  @property_managers << pm
  pm
end

#value_aliases(property, value) ⇒ Array<String>

Note:

propertyが値としてvalueを持たない場合や、プロパティが列挙型でない場合、空の配列が帰る

propertyのプロパティ値の中のvalueのエイリアスを全て取得



187
188
189
190
191
192
193
194
195
196
# File 'lib/uniprop/unicode_manager.rb', line 187

def value_aliases(property, value)
  return [] if !version.has_property?(property)
  prop = version.find_property(property)
  
  if prop.has_property_value?(value)
    prop.find_property_value(value).uncanonicaled_aliases
  else
    []
  end
end

#values_of(property, char) ⇒ String/Array<String>

propertyプロパティのcodepointのプロパティ値を取得



134
135
136
# File 'lib/uniprop/unicode_manager.rb', line 134

def values_of(property, char)      
  property_manager(property).values_of(char.ord)
end