class Stringex::Localization::Converter
Attributes
Public Class Methods
Source
# File lib/stringex/localization/converter.rb 12 def initialize(string, options = {}) 13 @string = string.dup 14 @options = Stringex::Configuration::StringExtensions.default_settings.merge(options) 15 string =~ /^(\s+)/ 16 @starting_whitespace = $1 unless $1 == '' 17 string =~ /(\s+)$/ 18 @ending_whitespace = $1 unless $1 == '' 19 end
Public Instance Methods
Source
# File lib/stringex/localization/converter.rb 21 def cleanup_accented_html_entities! 22 string.gsub! expressions.accented_html_entity, '\1' 23 end
Source
# File lib/stringex/localization/converter.rb 25 def cleanup_characters! 26 string.gsub! expressions.cleanup_characters, ' ' 27 end
Source
# File lib/stringex/localization/converter.rb 29 def cleanup_html_entities! 30 string.gsub! expressions.cleanup_html_entities, '' 31 end
Source
# File lib/stringex/localization/converter.rb 33 def cleanup_smart_punctuation! 34 expressions.smart_punctuation.each do |expression, replacement| 35 string.gsub! expression, replacement 36 end 37 end
Source
# File lib/stringex/localization/converter.rb 39 def normalize_currency! 40 string.gsub!(/(\d+),(\d+)/, '\1\2') 41 end
Source
# File lib/stringex/localization/converter.rb 43 def smart_strip! 44 string.strip! 45 @string = "#{starting_whitespace}#{string}#{ending_whitespace}" 46 end
Source
# File lib/stringex/localization/converter.rb 48 def strip! 49 string.strip! 50 end
Source
# File lib/stringex/localization/converter.rb 56 def translate!(*conversions) 57 conversions.each do |conversion| 58 send conversion 59 end 60 end
Protected Instance Methods
Source
# File lib/stringex/localization/converter.rb 68 def abbreviations 69 string.gsub! expressions.abbreviation do |x| 70 x.gsub '.', '' 71 end 72 end
Source
# File lib/stringex/localization/converter.rb 74 def apostrophes 75 string.gsub! expressions.apostrophe, '\1\2' 76 end
Source
# File lib/stringex/localization/converter.rb 78 def characters 79 expressions.characters.each do |key, expression| 80 next if key == :slash && options[:allow_slash] 81 replacement = translate(key) 82 replacement = " #{replacement} " unless replacement == '' || key == :dot 83 string.gsub! expression, replacement 84 end 85 end
Source
# File lib/stringex/localization/converter.rb 87 def currencies 88 if has_currencies? 89 [:currencies_complex, :currencies_simple].each do |type| 90 expressions.send(type).each do |key, expression| 91 string.gsub! expression, " #{translate(key, :currencies)} " 92 end 93 end 94 end 95 end
Source
# File lib/stringex/localization/converter.rb 97 def ellipses 98 string.gsub! expressions.characters[:ellipsis], " #{translate(:ellipsis)} " 99 end
Source
# File lib/stringex/localization/converter.rb 101 def html_entities 102 expressions.html_entities.each do |key, expression| 103 string.gsub! expression, translate(key, :html_entities) 104 end 105 string.squeeze! ' ' 106 end
Source
# File lib/stringex/localization/converter.rb 64 def unreadable_control_characters 65 string.gsub! expressions.unreadable_control_characters, '' 66 end
Source
# File lib/stringex/localization/converter.rb 108 def vulgar_fractions 109 expressions.vulgar_fractions.each do |key, expression| 110 string.gsub! expression, translate(key, :vulgar_fractions) 111 end 112 end
Private Instance Methods
Source
# File lib/stringex/localization/converter.rb 116 def expressions 117 ConversionExpressions 118 end
Source
# File lib/stringex/localization/converter.rb 120 def has_currencies? 121 string =~ CURRENCIES_SUPPORTED 122 end
Source
# File lib/stringex/localization/converter.rb 124 def translate(key, scope = :characters) 125 Localization.translate scope, key 126 end