Class: ActiveSupport::Multibyte::Handlers::UnicodeDatabase
- Defined in:
- lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb,
lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/generators/generate_tables.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#boundary ⇒ Object
Returns the value of attribute boundary.
-
#codepoints ⇒ Object
Returns the value of attribute codepoints.
-
#composition_exclusion ⇒ Object
Returns the value of attribute composition_exclusion.
-
#composition_map ⇒ Object
Returns the value of attribute composition_map.
-
#cp1252 ⇒ Object
Returns the value of attribute 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.
-
.load ⇒ Object
Loads the unicode database and returns all the internal objects of UnicodeDatabase.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Shortcut to ucd.codepoints[].
-
#initialize ⇒ UnicodeDatabase
constructor
Creates a new UnicodeDatabase instance and loads the database.
Constructor Details
#initialize ⇒ UnicodeDatabase
Creates a new UnicodeDatabase instance and loads the database.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 13 def initialize begin @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = self.class.load rescue Exception => e raise IOError.new("Couldn't load the unicode tables for UTF8Handler (#{e.}), handler is unusable") end @codepoints ||= Hash.new(Codepoint.new) @composition_exclusion ||= [] @composition_map ||= {} @boundary ||= {} @cp1252 ||= {} # 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 end |
Instance Attribute Details
#boundary ⇒ Object
Returns the value of attribute boundary.
10 11 12 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10 def boundary @boundary end |
#codepoints ⇒ Object
Returns the value of attribute codepoints.
10 11 12 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10 def codepoints @codepoints end |
#composition_exclusion ⇒ Object
Returns the value of attribute composition_exclusion.
10 11 12 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10 def composition_exclusion @composition_exclusion end |
#composition_map ⇒ Object
Returns the value of attribute composition_map.
10 11 12 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10 def composition_map @composition_map end |
#cp1252 ⇒ Object
Returns the value of attribute cp1252.
10 11 12 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10 def cp1252 @cp1252 end |
Class Method Details
.dirname ⇒ Object
Returns the directory in which the data files are stored
39 40 41 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 39 def self.dirname File.dirname(__FILE__) + '/../../values/' end |
.filename ⇒ Object
Returns the filename for the data file for this version
44 45 46 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 44 def self.filename File. File.join(dirname, "unicode_tables.dat") end |
.load ⇒ Object
Loads the unicode database and returns all the internal objects of UnicodeDatabase
49 50 51 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 49 def self.load File.open(self.filename, 'rb') { |f| Marshal.load f.read } end |
Instance Method Details
#[](index) ⇒ Object
Shortcut to ucd.codepoints[]
36 |
# File 'lib/gems/unicodechars-0.0.2/lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 36 def [](index); @codepoints[index]; end |