Class: L10nizer::KeyGenerator
- Inherits:
-
Object
- Object
- L10nizer::KeyGenerator
- Defined in:
- lib/l10nizer/keygen.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
- #call(string) ⇒ Object
-
#initialize ⇒ KeyGenerator
constructor
A new instance of KeyGenerator.
Constructor Details
#initialize ⇒ KeyGenerator
Returns a new instance of KeyGenerator.
5 6 7 |
# File 'lib/l10nizer/keygen.rb', line 5 def initialize @seen = {} end |
Instance Attribute Details
#namespace ⇒ Object
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 |