Class: L10nizer::KeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/l10nizer/keygen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyGenerator

Returns a new instance of KeyGenerator.



5
6
7
# File 'lib/l10nizer/keygen.rb', line 5

def initialize
  @seen = {}
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

Instance Method Details

#call(string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/l10nizer/keygen.rb', line 9

def call(string)
  provisional = [make_safe(namespace), make_safe(string)].compact * "."

  until distinct?(provisional, string)
    match = provisional.match(/_(\d+)$/)
    if match
      provisional = provisional.sub(/\d+$/, match[1].to_i.succ.to_s)
    else
      provisional += "_1"
    end
  end

  provisional
end