Class: UniProp::Property

Inherits:
Object
  • Object
show all
Includes:
Alias
Defined in:
lib/uniprop/unicode_elements.rb

Instance Attribute Summary collapse

Attributes included from Alias

#longest_alias

Instance Method Summary collapse

Methods included from Alias

#add_alias, #aliases, canonical, #eql?, #has_alias?, #hash, #inspect, #uncanonicaled_aliases

Constructor Details

#initialize(version, *new_aliases) ⇒ Property

Returns a new instance of Property.



66
67
68
69
# File 'lib/uniprop/unicode_elements.rb', line 66

def initialize(version, *new_aliases)
  @version = version
  super(*new_aliases)
end

Instance Attribute Details

#property_value_typeObject

Returns the value of attribute property_value_type.



62
63
64
# File 'lib/uniprop/unicode_elements.rb', line 62

def property_value_type
  @property_value_type
end

#versionObject (readonly)

Returns the value of attribute version.



62
63
64
# File 'lib/uniprop/unicode_elements.rb', line 62

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/uniprop/unicode_elements.rb', line 99

def ==(other)
  # プロパティのエイリアスはバージョン更新時に増えることがあるため、versionの異なるPropertyを比較する場合には、プロパティが増えていてもtrueを返す
  if version > other.version
    return (other.aliases-aliases).empty?
  elsif version < other.version
    return (aliases-other.aliases).empty?
  else
    aliases==other.aliases
  end
end

#actual_columns(propfile) ⇒ Array<Integer>

Note:

プロパティがpropfileに含まれない場合、空の配列を返す

propfile中でプロパティが含まれる列を取得

Parameters:

Returns:

  • (Array<Integer>)


151
152
153
154
155
# File 'lib/uniprop/unicode_elements.rb', line 151

def actual_columns(propfile)
  columns = []
  actual_positions.each { columns<<_1.column if _1.propfile==propfile }
  columns
end

#actual_positionsArray<Position>

:nocov: versionに含まれるPropFileの中の、このプロパティが含まれる場所を取得

Returns:



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

def actual_positions
  @actual_positions ||= version..property_to_actual_positions[self]
end

#find_property_value(property_value_alias) ⇒ PropertyValue

property_value_aliasをエイリアスに持つPropertyValueをproperty_valuesの中から取得

Parameters:

  • property_value_alias (String)

Returns:

Raises:



129
130
131
132
133
134
135
136
137
# File 'lib/uniprop/unicode_elements.rb', line 129

def find_property_value(property_value_alias)
  pv = property_values.find { _1.has_alias?(property_value_alias)}
  
  if pv
    return pv
  else
    raise(PropertyValueNotFoundError, "#{longest_alias} doesn't have #{property_value_alias} as value.")
  end
end

#has_property_value?(property_value_alias) ⇒ Boolean

:nocov: property_value_aliasをエイリアスに持つPropertyValueをproperty_valuesに持つか判定

Parameters:

  • property_value_alias (String)

Returns:

  • (Boolean)


118
119
120
121
122
# File 'lib/uniprop/unicode_elements.rb', line 118

def has_property_value?(property_value_alias)
  !!find_property_value(property_value_alias)
rescue
  false
end

#is_unihan_property?Boolean

Unihanのプロパティか判定

Returns:

  • (Boolean)


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

def is_unihan_property?
  version.unihan_properties.include?(self)
end

#miscellaneous_formatSymbol?

settings.rbのmiscellaneous_formats内のformat_typeを小文字のシンボルで取得。記述されていない場合はnil

Returns:

  • (Symbol?)


89
90
91
# File 'lib/uniprop/unicode_elements.rb', line 89

def miscellaneous_format
  version.property_to_miscellaneous_formats.dig(self, :format_type)&.downcase&.to_sym
end

#property_valuesArray<PropertyValue>

Returns:



111
112
113
# File 'lib/uniprop/unicode_elements.rb', line 111

def property_values
  version.property_to_property_values[self]
end

#unique_thresholdInteger?/Float?

settings.rbのmiscellaneous_formats内のunique_thresholdを取得。記述されていない場合はnil

Returns:

  • (Integer?/Float?)


95
96
97
# File 'lib/uniprop/unicode_elements.rb', line 95

def unique_threshold
  version.property_to_miscellaneous_formats.dig(self, :unique_threshold)
end