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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boundary=(value) ⇒ Object (writeonly)

Sets the attribute boundary

Parameters:

  • value

    the value to set the attribute boundary to.



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

def boundary=(value)
  @boundary = value
end

#codepoints=(value) ⇒ Object (writeonly)

Sets the attribute codepoints

Parameters:

  • value

    the value to set the attribute codepoints to.



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

def codepoints=(value)
  @codepoints = value
end

#composition_exclusion=(value) ⇒ Object (writeonly)

Sets the attribute composition_exclusion

Parameters:

  • value

    the value to set the attribute composition_exclusion to.



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

def composition_exclusion=(value)
  @composition_exclusion = value
end

#composition_map=(value) ⇒ Object (writeonly)

Sets the attribute composition_map

Parameters:

  • value

    the value to set the attribute composition_map to.



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

def composition_map=(value)
  @composition_map = value
end

#cp1252=(value) ⇒ Object (writeonly)

Sets the attribute cp1252

Parameters:

  • value

    the value to set the attribute cp1252 to.



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

def cp1252=(value)
  @cp1252 = value
end

Class Method Details

.dirnameObject

Returns the directory in which the data files are stored



26
27
28
# File 'lib/active_support/multibyte/handlers/utf8_handler.rb', line 26

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

.filenameObject

Returns the filename for the data file for this version



31
32
33
# File 'lib/active_support/multibyte/handlers/utf8_handler.rb', line 31

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

.loadObject



11
12
13
# File 'lib/active_support/multibyte/generators/generate_tables.rb', line 11

def self.load
  [Hash.new(Codepoint.new),[],{},{}]
end

Instance Method Details

#[](index) ⇒ Object

Shortcut to ucd.codepoints[]



23
# File 'lib/active_support/multibyte/handlers/utf8_handler.rb', line 23

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

#loadObject

Loads the unicode database and returns all the internal objects of UnicodeDatabase Once the values have been loaded, define attr_reader methods for the instance variables.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_support/multibyte/handlers/utf8_handler.rb', line 37

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}), 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

  # define attr_reader methods for the instance variables
  class << self
    attr_reader :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252
  end
end