class Stringex::Localization::Converter
Attributes
ending_whitespace[R]
options[R]
starting_whitespace[R]
string[R]
Public Class Methods
new(string, options = {})
click to toggle source
# File lib/stringex/localization/converter.rb, line 11 def initialize(string, options = {}) @string = string.dup @options = Stringex::Configuration::StringExtensions.default_settings.merge(options) string =~ /^(\s+)/ @starting_whitespace = $1 unless $1 == '' string =~ /(\s+)$/ @ending_whitespace = $1 unless $1 == '' end
Public Instance Methods
cleanup_accented_html_entities!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 20 def cleanup_accented_html_entities! string.gsub! expressions.accented_html_entity, '\1' end
cleanup_characters!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 24 def cleanup_characters! string.gsub! expressions.cleanup_characters, ' ' end
cleanup_html_entities!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 28 def cleanup_html_entities! string.gsub! expressions.cleanup_html_entities, '' end
cleanup_smart_punctuation!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 32 def cleanup_smart_punctuation! expressions.smart_punctuation.each do |expression, replacement| string.gsub! expression, replacement end end
normalize_currency!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 38 def normalize_currency! string.gsub! /(\d+),(\d+)/, '\1\2' end
smart_strip!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 42 def smart_strip! string.strip! @string = "#{starting_whitespace}#{string}#{ending_whitespace}" end
strip!()
click to toggle source
# File lib/stringex/localization/converter.rb, line 47 def strip! string.strip! end
translate!(*conversions)
click to toggle source
# File lib/stringex/localization/converter.rb, line 55 def translate!(*conversions) conversions.each do |conversion| send conversion end end
Protected Instance Methods
abbreviations()
click to toggle source
# File lib/stringex/localization/converter.rb, line 67 def abbreviations string.gsub! expressions.abbreviation do |x| x.gsub '.', '' end end
apostrophes()
click to toggle source
# File lib/stringex/localization/converter.rb, line 73 def apostrophes string.gsub! expressions.apostrophe, '\1\2' end
characters()
click to toggle source
# File lib/stringex/localization/converter.rb, line 77 def characters expressions.characters.each do |key, expression| next if key == :slash && options[:allow_slash] replacement = translate(key) replacement = " #{replacement} " unless replacement == '' || key == :dot string.gsub! expression, replacement end end
currencies()
click to toggle source
# File lib/stringex/localization/converter.rb, line 86 def currencies if has_currencies? [:currencies_complex, :currencies_simple].each do |type| expressions.send(type).each do |key, expression| string.gsub! expression, " #{translate(key, :currencies)} " end end end end
ellipses()
click to toggle source
# File lib/stringex/localization/converter.rb, line 96 def ellipses string.gsub! expressions.characters[:ellipsis], " #{translate(:ellipsis)} " end
html_entities()
click to toggle source
# File lib/stringex/localization/converter.rb, line 100 def html_entities expressions.html_entities.each do |key, expression| string.gsub! expression, translate(key, :html_entities) end string.squeeze! ' ' end
unreadable_control_characters()
click to toggle source
# File lib/stringex/localization/converter.rb, line 63 def unreadable_control_characters string.gsub! expressions.unreadable_control_characters, '' end
vulgar_fractions()
click to toggle source
# File lib/stringex/localization/converter.rb, line 107 def vulgar_fractions expressions.vulgar_fractions.each do |key, expression| string.gsub! expression, translate(key, :vulgar_fractions) end end
Private Instance Methods
expressions()
click to toggle source
# File lib/stringex/localization/converter.rb, line 115 def expressions ConversionExpressions end
has_currencies?()
click to toggle source
# File lib/stringex/localization/converter.rb, line 119 def has_currencies? string =~ CURRENCIES_SUPPORTED end
translate(key, scope = :characters)
click to toggle source
# File lib/stringex/localization/converter.rb, line 123 def translate(key, scope = :characters) Localization.translate scope, key end