Class: Erector::UnicodeBuilder
Overview
Note that this class is only used in building erector itself (and even then, only needs to be run when there is a new UnicodeData.txt file from unicode.org).
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(input, output) ⇒ UnicodeBuilder
constructor
A new instance of UnicodeBuilder.
- #namify(name) ⇒ Object
- #output(name, code_point) ⇒ Object
- #output_line(line) ⇒ Object
- #process_file ⇒ Object
- #process_line(line) ⇒ Object
Constructor Details
#initialize(input, output) ⇒ UnicodeBuilder
Returns a new instance of UnicodeBuilder.
6 7 8 9 10 |
# File 'lib/erector/unicode_builder.rb', line 6 def initialize(input, output) @input = input @output = output @first = true end |
Instance Method Details
#generate ⇒ Object
12 13 14 15 16 |
# File 'lib/erector/unicode_builder.rb', line 12 def generate() @output.puts "Erector::CHARACTERS = {" process_file @output.puts "}" end |
#namify(name) ⇒ Object
62 63 64 |
# File 'lib/erector/unicode_builder.rb', line 62 def namify(name) name.downcase.gsub(/[- ]/, '_') end |
#output(name, code_point) ⇒ Object
58 59 60 |
# File 'lib/erector/unicode_builder.rb', line 58 def output(name, code_point) output_line " :#{namify(name)} => 0x#{code_point.downcase}" end |
#output_line(line) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/erector/unicode_builder.rb', line 32 def output_line(line) if (!@first) @output.puts(',') end @output.print(line) @first = false end |
#process_file ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/erector/unicode_builder.rb', line 18 def process_file() while !@input.eof line = @input.gets.strip if (line == "") next; end process_line(line) end if (!@first) @output.puts end end |
#process_line(line) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/erector/unicode_builder.rb', line 42 def process_line(line) fields = line.split(';') code_point = fields[0] name = fields[1] alternate_name = fields[10] if /^</.match(name) return "" end output name, code_point if (!alternate_name.nil? && alternate_name != "") output alternate_name, code_point end end |