Module: Unbork

Defined in:
lib/unbork.rb

Class Method Summary collapse

Class Method Details

.learn_swedishObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/unbork.rb', line 7

def learn_swedish
  subst_filename = File.join(File.dirname(__FILE__), 'unmangle-utf8-script.sed')
  swedish = {}
  File.open(subst_filename).each do |line|
    next if line =~ /latin1/
    s, borked, unborked, g = line.split('/')
    swedish[borked] = unborked
  end
  swedish
end

.swedishObject



3
4
5
# File 'lib/unbork.rb', line 3

def swedish
  @@swedish ||= learn_swedish
end

.swedish_lettersObject



18
19
20
# File 'lib/unbork.rb', line 18

def swedish_letters
  Regexp.union(swedish.keys)
end

.unbork(text) ⇒ Object



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

def unbork text
  if RUBY_VERSION > "1.9"
    text.gsub(swedish_letters, swedish)
  else
    text.gsub(swedish_letters) do |match|
      swedish[match]
    end
  end
end