Class: TwitterCldr::LocalizedString
- Inherits:
-
LocalizedObject
- Object
- LocalizedObject
- TwitterCldr::LocalizedString
- 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
-
#%(args) ⇒ Object
Uses wrapped string object as a format specification and returns the result of applying it to
args
(seeTwitterCldr::Utils.interpolate
method for interpolation syntax). - #code_points ⇒ Object
- #formatter_const ⇒ Object
- #normalize(options = {}) ⇒ Object
- #to_s ⇒ Object
Methods inherited from LocalizedObject
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_points ⇒ Object
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_const ⇒ Object
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( = {}) [:using] ||= :NFD if VALID_NORMALIZERS.include?([:using]) normalizer_const = TwitterCldr::Normalizers.const_get([: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_s ⇒ Object
46 47 48 |
# File 'lib/twitter_cldr/core_ext/string.rb', line 46 def to_s @base_obj.dup end |