Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rake task for updating canonical compositions.
- Loading branch information
Showing
6 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/twitter_cldr/resources/canonical_compositions_updater.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# encoding: UTF-8 | ||
|
||
# Copyright 2012 Twitter, Inc | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
#require 'yaml' | ||
|
||
module TwitterCldr | ||
module Resources | ||
|
||
class CanonicalCompositionsUpdater | ||
|
||
CODE_POINT_MAX = 0x10FFFF | ||
|
||
# Arguments: | ||
# | ||
# output_path - output directory for generated YAML file | ||
# | ||
def initialize(output_path) | ||
@output_path = output_path | ||
end | ||
|
||
def update | ||
File.open(File.join(@output_path, 'canonical_compositions.yml'), 'w') do |output| | ||
YAML.dump(generate_compositions, output) | ||
end | ||
end | ||
|
||
private | ||
|
||
def generate_compositions | ||
(1..CODE_POINT_MAX).inject({}) do |memo, code_point| | ||
code_point_data = TwitterCldr::Shared::CodePoint.find(code_point) | ||
|
||
if code_point_data && !code_point_data.compatibility_decomposition? && code_point_data.decomposition && !code_point_data.decomposition.empty? | ||
memo[code_point_data.decomposition] = code_point | ||
end | ||
|
||
log_progress(code_point, memo.size) | ||
|
||
memo | ||
end | ||
end | ||
|
||
def log_progress(code_point, compositions_count) | ||
$stdout.write("\r#{(100.0 * code_point / CODE_POINT_MAX).round}% complete, found #{compositions_count} canonical compositions") | ||
$stdout.write("\n") if code_point == CODE_POINT_MAX | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters