Class: TwitterCldr::LocalizedString

Inherits:
LocalizedObject show all
Defined in:
lib/twitter_cldr/core_ext/string.rb

Constant Summary collapse

VALID_NORMALIZERS =
[:NFD, :NFKD]

Instance Attribute Summary

Attributes inherited from LocalizedObject

#base_obj, #formatter, #locale

Instance Method Summary collapse

Methods inherited from LocalizedObject

#initialize

Constructor Details

This class inherits a constructor from TwitterCldr::LocalizedObject

Instance Method Details

#%(args) ⇒ Object

Uses wrapped string object as a format specification and returns the result of applying it to args (see TwitterCldr::Utils.interpolate method for interpolation syntax).

If args is a Hash than pluralization is performed before interpolation (see PluralFormatter class for pluralization specification).



22
23
24
25
# File 'lib/twitter_cldr/core_ext/string.rb', line 22

def %(args)
  pluralized = args.is_a?(Hash) ? @formatter.format(@base_obj, args) : @base_obj
  TwitterCldr::Utils.interpolate(pluralized, args)
end

#code_pointsObject



42
43
44
# File 'lib/twitter_cldr/core_ext/string.rb', line 42

def code_points
  TwitterCldr::Utils::CodePoints.from_string(@base_obj)
end

#formatter_constObject



27
28
29
# File 'lib/twitter_cldr/core_ext/string.rb', line 27

def formatter_const
  TwitterCldr::Formatters::PluralFormatter
end

#normalize(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/twitter_cldr/core_ext/string.rb', line 31

def normalize(options = {})
  options[:using] ||= :NFD

  if VALID_NORMALIZERS.include?(options[:using])
    normalizer_const = TwitterCldr::Normalizers.const_get(options[:using])
    LocalizedString.new(normalizer_const.normalize(@base_obj), @locale)
  else
    raise ArgumentError.new("Invalid normalization form specified with :using option.  Choices are [#{VALID_NORMALIZERS.map(&:to_s).join(", ")}]")
  end
end

#to_sObject



46
47
48
# File 'lib/twitter_cldr/core_ext/string.rb', line 46

def to_s
  @base_obj.dup
end