Class: Jologs::Jologize

Inherits:
Object
  • Object
show all
Defined in:
lib/jologs/jologize.rb

Constant Summary collapse

@@dictionary =
nil

Class Method Summary collapse

Class Method Details

.dictionaryObject



24
25
26
# File 'lib/jologs/jologize.rb', line 24

def dictionary
  @@dictionary
end

.jologize(str) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jologs/jologize.rb', line 11

def jologize(str)
  result = str
  dictionary.each do |jolog_word, normal_word|
    begin
      # result = result.gsub(normal_word, jolog_word)
      result = result.gsub(Regexp.new("#{normal_word}", [Regexp::IGNORECASE, Regexp::MULTILINE]), jolog_word)
    rescue Exception => e
      puts "Halted on #{normal_word} #{jolog_word} : #{e.message}"
    end
  end
  result
end

.load_dictionary!(file) ⇒ Object



28
29
30
# File 'lib/jologs/jologize.rb', line 28

def load_dictionary!(file)
  @@dictionary = YAML.load_file(file)
end

.translate(str) ⇒ Object



7
8
9
# File 'lib/jologs/jologize.rb', line 7

def translate(str)
  jologize(str)
end