class Ipa
Constants
- ROOT
Attributes
timeout[RW]
Public Class Methods
new()
click to toggle source
# File lib/ipa.rb, line 12 def initialize @timeout = 0.2 end
Public Instance Methods
conversion()
click to toggle source
# File lib/ipa.rb, line 24 def conversion @conversion ||= parseCSV "conversion" end
convert_to_ipa(texte)
click to toggle source
# File lib/ipa.rb, line 28 def convert_to_ipa(texte) texte = texte.downcase texte.gsub(SPE, "").split.map do |mot| exceptions[mot] || "".tap do |result| Timeout::timeout(timeout) do conversion.select { |regle| mot =~ /#{regle}/ }.first.tap do |regle, api| mot.sub! /#{regle}/, "" result << api.to_s end until mot.empty? end end end rescue Timeout::Error return [] end
exceptions()
click to toggle source
# File lib/ipa.rb, line 20 def exceptions @exceptions ||= JSON.parse(File.read("#{ROOT}/data/dict.json")) end
parseCSV(path)
click to toggle source
# File lib/ipa.rb, line 16 def parseCSV(path) Hash[File.open("#{ROOT}/data/#{path}.csv").read.split("\n").map {|ligne| ligne.split("#")}] end