Module: Interscript
- Defined in:
- lib/interscript.rb,
lib/interscript/version.rb
Overview
Transliteration
Constant Summary collapse
- SYSTEM_DEFINITIONS_PATH =
File.('../maps', __dir__)
- VERSION =
"0.1.2"
Class Method Summary collapse
- .load_system_definition(system_code) ⇒ Object
- .transliterate(system_code, string) ⇒ Object
- .transliterate_file(system_code, input_file, output_file) ⇒ Object
Class Method Details
.load_system_definition(system_code) ⇒ Object
20 21 22 |
# File 'lib/interscript.rb', line 20 def load_system_definition(system_code) YAML.load_file(File.join(SYSTEM_DEFINITIONS_PATH, "#{system_code}.yaml")) end |
.transliterate(system_code, string) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/interscript.rb', line 24 def transliterate(system_code, string) system = load_system_definition(system_code) rules = system["map"]["rules"] || [] charmap = system["map"]["characters"] || {} rules.each do |r| string.gsub! %r{#{r["pattern"]}}, r["result"] end string.split('').map do |char| charmap[char] || char end.join('') end |
.transliterate_file(system_code, input_file, output_file) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/interscript.rb', line 10 def transliterate_file(system_code, input_file, output_file) input = File.read(input_file) output = transliterate(system_code, input) File.open(output_file, "w") do |f| f.puts(output) end puts "Output written to: #{output_file}" end |