Class: ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- Inherits:
-
Object
- Object
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- Defined in:
- activesupport/lib/active_support/multibyte/unicode.rb
Overview
Holds static data from the Unicode database
Constant Summary
- ATTRIBUTES =
:codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252
Class Method Summary (collapse)
-
+ (Object) dirname
Returns the directory in which the data files are stored.
-
+ (Object) filename
Returns the filename for the data file for this version.
Instance Method Summary (collapse)
-
- (UnicodeDatabase) initialize
constructor
A new instance of UnicodeDatabase.
-
- (Object) load
Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
Constructor Details
- (UnicodeDatabase) initialize
A new instance of UnicodeDatabase
323 324 325 326 327 328 329 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 323 def initialize @codepoints = Hash.new(Codepoint.new) @composition_exclusion = [] @composition_map = {} @boundary = {} @cp1252 = {} end |
Class Method Details
+ (Object) dirname
Returns the directory in which the data files are stored
365 366 367 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 365 def self.dirname File.dirname(__FILE__) + '/../values/' end |
+ (Object) filename
Returns the filename for the data file for this version
370 371 372 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 370 def self.filename File. File.join(dirname, "unicode_tables.dat") end |
Instance Method Details
- (Object) load
Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 342 def load begin @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read } rescue Exception => e raise IOError.new("Couldn't load the Unicode tables for UTF8Handler (#{e.}), ActiveSupport::Multibyte is unusable") end # Redefine the === method so we can write shorter rules for grapheme cluster breaks @boundary.each do |k,_| @boundary[k].instance_eval do def ===(other) detect { |i| i === other } ? true : false end end if @boundary[k].kind_of?(Array) end # define attr_reader methods for the instance variables class << self attr_reader(*ATTRIBUTES) end end |