Sha256: ae0deb018dfe61e11c70292f864352da40e39478de201d8152957455b0d8bd78

Contents?: true

Size: 632 Bytes

Versions: 22

Compression:

Stored size: 632 Bytes

Contents

module Babelyoda
  module Regexp
    PLURAL_ID = /([^%]|^)%\[(one|some|many|none|plural)\]([^\s])/
    PLURALIZED_ID = /([^%]|^)%\[(plural)\]([^\s])/
    
    def plural_id?(id)
      plural_match(id) != nil
    end
    
    def plural_match(id)
      id.match(PLURAL_ID)
    end
    
    def depluralize_value(id)
      id.gsub(PLURAL_ID, '\1%\3')
    end

    def depluralize_key(id)
      id.gsub(PLURAL_ID, '\1%[plural]\3')
    end
    
    def pluralize_key(id, plural_key)
      id.gsub(PLURALIZED_ID, "\\1%[#{plural_key}]\\3")
    end
    
    def extract_plural_key(id)
      id.match(PLURAL_ID)[2].to_sym
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
babelyoda-2.2.0 lib/babelyoda/regexp.rb
babelyoda-2.1.20 lib/babelyoda/regexp.rb
babelyoda-2.1.19 lib/babelyoda/regexp.rb
babelyoda-2.1.18 lib/babelyoda/regexp.rb
babelyoda-2.1.17 lib/babelyoda/regexp.rb
babelyoda-2.1.16 lib/babelyoda/regexp.rb
babelyoda-2.1.15 lib/babelyoda/regexp.rb
babelyoda-2.1.14 lib/babelyoda/regexp.rb
babelyoda-2.1.13 lib/babelyoda/regexp.rb
babelyoda-2.1.12 lib/babelyoda/regexp.rb
babelyoda-2.1.11 lib/babelyoda/regexp.rb
babelyoda-2.1.10 lib/babelyoda/regexp.rb
babelyoda-2.1.9 lib/babelyoda/regexp.rb
babelyoda-2.1.8 lib/babelyoda/regexp.rb
babelyoda-2.1.7 lib/babelyoda/regexp.rb
babelyoda-2.1.6 lib/babelyoda/regexp.rb
babelyoda-2.1.5 lib/babelyoda/regexp.rb
babelyoda-2.1.4 lib/babelyoda/regexp.rb
babelyoda-2.1.3 lib/babelyoda/regexp.rb
babelyoda-2.1.2 lib/babelyoda/regexp.rb