| 10 | | attr_accessor :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252 |
|---|
| 11 | | |
|---|
| 12 | | # Creates a new UnicodeDatabase instance and loads the database. |
|---|
| 13 | | def initialize |
|---|
| | 10 | attr_writer :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252 |
|---|
| | 11 | |
|---|
| | 12 | # self-expiring methods that lazily load the Unicode database and then return the value. |
|---|
| | 13 | [:codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252].each do |attr_name| |
|---|
| | 14 | class_eval(<<-EOS, __FILE__, __LINE__) |
|---|
| | 15 | def #{attr_name} |
|---|
| | 16 | load |
|---|
| | 17 | @#{attr_name} |
|---|
| | 18 | end |
|---|
| | 19 | EOS |
|---|
| | 20 | end |
|---|
| | 21 | |
|---|
| | 22 | # Shortcut to ucd.codepoints[] |
|---|
| | 23 | def [](index); codepoints[index]; end |
|---|
| | 24 | |
|---|
| | 25 | # Returns the directory in which the data files are stored |
|---|
| | 26 | def self.dirname |
|---|
| | 27 | File.dirname(__FILE__) + '/../../values/' |
|---|
| | 28 | end |
|---|
| | 29 | |
|---|
| | 30 | # Returns the filename for the data file for this version |
|---|
| | 31 | def self.filename |
|---|
| | 32 | File.expand_path File.join(dirname, "unicode_tables.dat") |
|---|
| | 33 | end |
|---|
| | 34 | |
|---|
| | 35 | # Loads the unicode database and returns all the internal objects of UnicodeDatabase |
|---|
| | 36 | # Once the values have been loaded, define attr_reader methods for the instance variables. |
|---|
| | 37 | def load |
|---|
| 33 | | end |
|---|
| 34 | | |
|---|
| 35 | | # Shortcut to ucd.codepoints[] |
|---|
| 36 | | def [](index); @codepoints[index]; end |
|---|
| 37 | | |
|---|
| 38 | | # Returns the directory in which the data files are stored |
|---|
| 39 | | def self.dirname |
|---|
| 40 | | File.dirname(__FILE__) + '/../../values/' |
|---|
| 41 | | end |
|---|
| 42 | | |
|---|
| 43 | | # Returns the filename for the data file for this version |
|---|
| 44 | | def self.filename |
|---|
| 45 | | File.expand_path File.join(dirname, "unicode_tables.dat") |
|---|
| 46 | | end |
|---|
| 47 | | |
|---|
| 48 | | # Loads the unicode database and returns all the internal objects of UnicodeDatabase |
|---|
| 49 | | def self.load |
|---|
| 50 | | File.open(self.filename, 'rb') { |f| Marshal.load f.read } |
|---|
| | 57 | |
|---|
| | 58 | # define attr_reader methods for the instance variables |
|---|
| | 59 | class << self |
|---|
| | 60 | attr_reader :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252 |
|---|
| | 61 | end |
|---|