class I18n::Magic::Helpers::StringOps
Public Class Methods
letters_only(text)
click to toggle source
# File lib/i18n/magic/helpers/string_ops.rb, line 25 def self.letters_only(text) text.gsub(%r/[0-9]|\^|\[|\]|\\|\||\/|[ !?.,@#$%&*(){}:'"`<>]/, '').strip.downcase end
locale(text, locale_files_path = I18n::Magic::Helpers::Environment::LOCALE_FILES_PATH)
click to toggle source
# File lib/i18n/magic/helpers/string_ops.rb, line 11 def self.locale(text, locale_files_path = I18n::Magic::Helpers::Environment::LOCALE_FILES_PATH) locales = I18n::Magic::Helpers::Environment.locales(locale_files_path) text_locale = locales[0] score = 0 locales.each do |locale| locale_score = I18n::Magic::Entity::TranslationFile.new(locale, locale_files_path).compatibility_score(text) if locale_score > score text_locale = locale score = locale_score end end text_locale end
underscore(text)
click to toggle source
# File lib/i18n/magic/helpers/string_ops.rb, line 7 def self.underscore(text) text.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase end