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
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

cleanup_accented_html_entities!() click to toggle source
   # File lib/stringex/localization/converter.rb
21 def cleanup_accented_html_entities!
22   string.gsub! expressions.accented_html_entity, '\1'
23 end
cleanup_characters!() click to toggle source
   # File lib/stringex/localization/converter.rb
25 def cleanup_characters!
26   string.gsub! expressions.cleanup_characters, ' '
27 end
cleanup_html_entities!() click to toggle source
   # File lib/stringex/localization/converter.rb
29 def cleanup_html_entities!
30   string.gsub! expressions.cleanup_html_entities, ''
31 end
cleanup_smart_punctuation!() click to toggle 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
normalize_currency!() click to toggle source
   # File lib/stringex/localization/converter.rb
39 def normalize_currency!
40   string.gsub!(/(\d+),(\d+)/, '\1\2')
41 end
smart_strip!() click to toggle source
   # File lib/stringex/localization/converter.rb
43 def smart_strip!
44   string.strip!
45   @string = "#{starting_whitespace}#{string}#{ending_whitespace}"
46 end
strip!() click to toggle source
   # File lib/stringex/localization/converter.rb
48 def strip!
49   string.strip!
50 end
strip_html_tags!() click to toggle source
   # File lib/stringex/localization/converter.rb
52 def strip_html_tags!
53   string.gsub! expressions.html_tag, ''
54 end
translate!(*conversions) click to toggle 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

abbreviations() click to toggle source
   # File lib/stringex/localization/converter.rb
68 def abbreviations
69   string.gsub! expressions.abbreviation do |x|
70     x.gsub '.', ''
71   end
72 end
apostrophes() click to toggle source
   # File lib/stringex/localization/converter.rb
74 def apostrophes
75   string.gsub! expressions.apostrophe, '\1\2'
76 end
characters() click to toggle 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
currencies() click to toggle 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
ellipses() click to toggle source
   # File lib/stringex/localization/converter.rb
97 def ellipses
98   string.gsub! expressions.characters[:ellipsis], " #{translate(:ellipsis)} "
99 end
html_entities() click to toggle 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
unreadable_control_characters() click to toggle source
   # File lib/stringex/localization/converter.rb
64 def unreadable_control_characters
65   string.gsub! expressions.unreadable_control_characters, ''
66 end
vulgar_fractions() click to toggle 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

expressions() click to toggle source
    # File lib/stringex/localization/converter.rb
116 def expressions
117   ConversionExpressions
118 end
has_currencies?() click to toggle source
    # File lib/stringex/localization/converter.rb
120 def has_currencies?
121   string =~ CURRENCIES_SUPPORTED
122 end
translate(key, scope = :characters) click to toggle source
    # File lib/stringex/localization/converter.rb
124 def translate(key, scope = :characters)
125   Localization.translate scope, key
126 end