diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-24 15:54:19 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-24 15:54:19 +0100 |
commit | 38095b40997a08a0b7e5155da442fa77165ce556 (patch) | |
tree | b46b031fad2b6a7cbff9ef11e44997455cf5f63d /sources/languages | |
parent | 55550a88ff517d48ca6e56f720c4080fdb569ac9 (diff) | |
download | taginfo-38095b40997a08a0b7e5155da442fa77165ce556.tar taginfo-38095b40997a08a0b7e5155da442fa77165ce556.tar.gz |
Updated ruby import scripts
* Removed rubygems require which isn't needed any more in Ruby 1.9
* Updated transaction syntax to use blocks
* Updated copyright year
Diffstat (limited to 'sources/languages')
-rwxr-xr-x | sources/languages/import_subtag_registry.rb | 43 | ||||
-rwxr-xr-x | sources/languages/import_unicode_scripts.rb | 57 |
2 files changed, 49 insertions, 51 deletions
diff --git a/sources/languages/import_subtag_registry.rb b/sources/languages/import_subtag_registry.rb index ac3d17b..300b0fb 100755 --- a/sources/languages/import_subtag_registry.rb +++ b/sources/languages/import_subtag_registry.rb @@ -25,8 +25,6 @@ # #------------------------------------------------------------------------------ -require 'rubygems' - require 'sqlite3' class Subtag @@ -63,10 +61,13 @@ class Subtag end -dir = ARGV[0] || '.' +#------------------------------------------------------------------------------ +dir = ARGV[0] || '.' db = SQLite3::Database.new(dir + '/taginfo-languages.db') +#------------------------------------------------------------------------------ + registry_file = "#{dir}/language-subtag-registry" file_date = nil @@ -101,27 +102,25 @@ end SUBTAG_TYPES = %w( language script region variant ) -db.execute('BEGIN TRANSACTION'); - -Subtag.entries.each do |entry| - if SUBTAG_TYPES.include?(entry.type) && - entry.description != 'Private use' && - (entry.type != 'language' || (entry.scope != 'special' && entry.scope != 'collection')) && - (entry.type != 'script' || !entry.subtag.match(%r{^Z}) ) && - (entry.type != 'region' || entry.subtag.match(%r{^[A-Z]{2}$}) ) - db.execute("INSERT INTO subtags (stype, subtag, added, suppress_script, scope, description, prefix) VALUES (?, ?, ?, ?, ?, ?, ?)", - entry.type, - entry.subtag, - entry.added, - entry.suppress_script, - entry.scope, - entry.description, - entry.prefix - ) +db.transaction do |db| + Subtag.entries.each do |entry| + if SUBTAG_TYPES.include?(entry.type) && + entry.description != 'Private use' && + (entry.type != 'language' || (entry.scope != 'special' && entry.scope != 'collection')) && + (entry.type != 'script' || !entry.subtag.match(%r{^Z}) ) && + (entry.type != 'region' || entry.subtag.match(%r{^[A-Z]{2}$}) ) + db.execute("INSERT INTO subtags (stype, subtag, added, suppress_script, scope, description, prefix) VALUES (?, ?, ?, ?, ?, ?, ?)", + entry.type, + entry.subtag, + entry.added, + entry.suppress_script, + entry.scope, + entry.description, + entry.prefix + ) + end end end -db.execute('COMMIT'); - #-- THE END ------------------------------------------------------------------- diff --git a/sources/languages/import_unicode_scripts.rb b/sources/languages/import_unicode_scripts.rb index 7855a78..e946983 100755 --- a/sources/languages/import_unicode_scripts.rb +++ b/sources/languages/import_unicode_scripts.rb @@ -25,48 +25,47 @@ # #------------------------------------------------------------------------------ -require 'rubygems' - require 'sqlite3' dir = ARGV[0] || '.' - db = SQLite3::Database.new(dir + '/taginfo-languages.db') +#------------------------------------------------------------------------------ + property_value_alias_file = "#{dir}/PropertyValueAliases.txt" codepoint_script_mapping_file = "#{dir}/Scripts.txt" -db.execute('BEGIN TRANSACTION'); - -open(property_value_alias_file) do |file| - file.each do |line| - line.chomp! - if line.match(%r{^sc ;}) - (sc, script, name) = line.split(%r{\s*;\s*}) - db.execute("INSERT INTO unicode_scripts (script, name) VALUES (?, ?)", script, name) +db.transaction do |db| + open(property_value_alias_file) do |file| + file.each do |line| + line.chomp! + if line.match(%r{^sc ;}) + (sc, script, name) = line.split(%r{\s*;\s*}) + db.execute("INSERT INTO unicode_scripts (script, name) VALUES (?, ?)", script, name) + end end end -end -open(codepoint_script_mapping_file) do |file| - file.each do |line| - line.chomp! - line.sub!(%r{\s*#.*}, '') - next if line.match(%r{^$}) - (codes, script) = line.split(%r{\s+;\s+}) - if codes.match(%r{^[0-9A-F]{4,5}$}) - from = codes - to = codes - elsif codes.match(%r{^([0-9A-F]{4,5})..([0-9A-F]{4,5})$}) - from = $1 - to = $2 - else - puts "Line does not match: #{line}" - next + open(codepoint_script_mapping_file) do |file| + file.each do |line| + line.chomp! + line.sub!(%r{\s*#.*}, '') + next if line.match(%r{^$}) + (codes, script) = line.split(%r{\s+;\s+}) + if codes.match(%r{^[0-9A-F]{4,5}$}) + from = codes + to = codes + elsif codes.match(%r{^([0-9A-F]{4,5})..([0-9A-F]{4,5})$}) + from = $1 + to = $2 + else + puts "Line does not match: #{line}" + next + end + db.execute("INSERT INTO unicode_codepoint_script_mapping (codepoint_from, codepoint_to, name) VALUES (?, ?, ?)", from, to, script) end - db.execute("INSERT INTO unicode_codepoint_script_mapping (codepoint_from, codepoint_to, name) VALUES (?, ?, ?)", from, to, script) end end -db.execute('COMMIT'); +#-- THE END ------------------------------------------------------------------- |