Class: ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- Defined in:
- activesupport/lib/active_support/multibyte/unicode.rb
Overview
Holds static data from the Unicode database.
Constant Summary collapse
- ATTRIBUTES =
:codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252
Class Method Summary collapse
-
.dirname ⇒ Object
Returns the directory in which the data files are stored.
-
.filename ⇒ Object
Returns the filename for the data file for this version.
Instance Method Summary collapse
-
#initialize ⇒ UnicodeDatabase
constructor
A new instance of UnicodeDatabase.
-
#load ⇒ Object
Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
Constructor Details
#initialize ⇒ UnicodeDatabase
Returns a new instance of UnicodeDatabase.
301 302 303 304 305 306 307 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 301 def initialize @codepoints = Hash.new(Codepoint.new) @composition_exclusion = [] @composition_map = {} @boundary = {} @cp1252 = {} end |
Class Method Details
Instance Method Details
#load ⇒ Object
Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'activesupport/lib/active_support/multibyte/unicode.rb', line 321 def load begin @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read } rescue => 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 |