Class: ActiveSupport::Multibyte::Handlers::UnicodeDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/unicodechars/multibyte/handlers/utf8_handler.rb,
lib/unicodechars/multibyte/generators/generate_tables.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnicodeDatabase

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/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.message}), 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

#boundaryObject

Returns the value of attribute boundary.



10
11
12
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10

def boundary
  @boundary
end

#codepointsObject

Returns the value of attribute codepoints.



10
11
12
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10

def codepoints
  @codepoints
end

#composition_exclusionObject

Returns the value of attribute composition_exclusion.



10
11
12
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10

def composition_exclusion
  @composition_exclusion
end

#composition_mapObject

Returns the value of attribute composition_map.



10
11
12
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10

def composition_map
  @composition_map
end

#cp1252Object

Returns the value of attribute cp1252.



10
11
12
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 10

def cp1252
  @cp1252
end

Class Method Details

.dirnameObject

Returns the directory in which the data files are stored



39
40
41
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 39

def self.dirname
  File.dirname(__FILE__) + '/../../values/'
end

.filenameObject

Returns the filename for the data file for this version



44
45
46
# File 'lib/unicodechars/multibyte/handlers/utf8_handler.rb', line 44

def self.filename
  File.expand_path File.join(dirname, "unicode_tables.dat")
end

.loadObject

Loads the unicode database and returns all the internal objects of UnicodeDatabase



49
50
51
# File '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/unicodechars/multibyte/handlers/utf8_handler.rb', line 36

def [](index); @codepoints[index]; end