module IpaPhonetics
Constants
- ROOT
- VERSION
Public Class Methods
conversion()
click to toggle source
# File lib/ipa_phonetics.rb, line 22 def IpaPhonetics.conversion @conversion ||= parseCSV "conversion" end
exceptions()
click to toggle source
# File lib/ipa_phonetics.rb, line 18 def IpaPhonetics.exceptions @exceptions ||= JSON.parse(File.read("#{ROOT}/data/dict.json")) end
get(text)
click to toggle source
# File lib/ipa_phonetics.rb, line 34 def IpaPhonetics.get(text) text = text.downcase text.gsub(SPE, "").split.map do |word| exceptions[word] || "".tap do |result| Timeout::timeout(timeout) do conversion.select { |rule| word =~ /#{rule}/ }.first.tap do |rule, api| word.sub! /#{rule}/, "" result << api.to_s end until word.empty? end end end rescue Timeout::Error return [] end
parseCSV(path)
click to toggle source
# File lib/ipa_phonetics.rb, line 14 def IpaPhonetics.parseCSV(path) Hash[File.open("#{ROOT}/data/#{path}.csv").read.split("\n").map {|ligne| ligne.split("#")}] end
set_timeout(seconds)
click to toggle source
# File lib/ipa_phonetics.rb, line 26 def IpaPhonetics.set_timeout(seconds) @timeout = seconds end
timeout()
click to toggle source
# File lib/ipa_phonetics.rb, line 30 def IpaPhonetics.timeout @timeout end