Class: ActiveSupport::Multibyte::UnicodeDatabase
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.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.
16 17 18 19 20 21 22 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.rb', line 16 def initialize @codepoints = Hash.new(Codepoint.new) @composition_exclusion = [] @composition_map = {} @boundary = {} @cp1252 = {} end |
Class Method Details
.dirname ⇒ Object
Returns the directory in which the data files are stored
58 59 60 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.rb', line 58 def self.dirname File.dirname(__FILE__) + '/../values/' end |
.filename ⇒ Object
Returns the filename for the data file for this version
63 64 65 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.rb', line 63 def self.filename File. File.join(dirname, "unicode_tables.dat") end |
Instance Method Details
#load ⇒ Object
Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/multibyte/unicode_database.rb', line 35 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.message}), 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 |