Top Level Namespace

Constant Summary collapse

ROOT =
File.expand_path("../..", __FILE__)
SPE =
/([(0-9)|•|—|–|\-|,|?|!|^|\r|°|“|”|...|\u00a0|«|»|…|\\|\/|!|?|\"|\'|\[|\]|\(|\)|\]|<|>|=|+|%|$|&|#|;|*|:|}|{|`])/

Instance Method Summary collapse

Instance Method Details

#apion(texte) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/apion.rb', line 20

def apion(texte)
	texte = texte.downcase
	texte.gsub(SPE, "").split.map do |mot|
		exceptions[mot] || "".tap do |result|
			conversion.select { |regle| mot =~ /#{regle}/ }.first.tap do |regle, api|
				mot.sub! /#{regle}/, ""
				result << api.to_s
			end until mot.empty?
		end
	end
end

#conversionObject



16
17
18
# File 'lib/apion.rb', line 16

def conversion
	@conversion ||= parseCSV "conversion"
end

#exceptionsObject



12
13
14
# File 'lib/apion.rb', line 12

def exceptions
	@exceptions ||= JSON.parse(File.read("#{ROOT}/data/dict.json"))
end

#parseCSV(path) ⇒ Object



8
9
10
# File 'lib/apion.rb', line 8

def parseCSV(path)
	Hash[File.open("#{ROOT}/data/#{path}.csv").read.split("\n").map {|ligne| ligne.split("#")}]
end