class TwitterCldr::Localized::LocalizedString

Public Instance Methods

%(args) click to toggle source

Uses wrapped string object as a format specification and returns the result of applying it to args (see standard String#% method documentation for interpolation syntax).

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

# File lib/twitter_cldr/localized/localized_string.rb, line 18
def %(args)
  pluralized = args.is_a?(Hash) ? formatter.format(@base_obj, args) : @base_obj
  escape_plural_interpolation(pluralized) % args
end
[](index) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 119
def [](index)
  if index.is_a?(Range)
    TwitterCldr::Utils::CodePoints.to_string(code_points[index])
  else
    TwitterCldr::Utils::CodePoints.to_char(code_points[index])
  end
end
bytesize() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 115
def bytesize
  @base_obj.bytesize
end
casefold(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 27
def casefold(options = {})
  unless options.include?(:t)
    # Turkish and azerbaijani use the dotless i and therefore have a few
    # special casefolding rules. Note "az" is not actually supported yet.
    options[:t] = [:tr, :az].include?(locale)
  end

  TwitterCldr::Shared::Casefolder.
    casefold(@base_obj, options[:t]).
    localize(locale)
end
code_points() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 87
def code_points
  TwitterCldr::Utils::CodePoints.from_string(@base_obj)
end
downcase() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 39
def downcase
  self.class.new(
    TwitterCldr::Shared::Caser.downcase(@base_obj), locale
  )
end
each()
Alias for: each_char
each_char() { |to_char| ... } click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 127
def each_char
  if block_given?
    code_points.each do |code_point|
      yield TwitterCldr::Utils::CodePoints.to_char(code_point)
    end
    @base_obj
  else
    code_points.map { |code_point| TwitterCldr::Utils::CodePoints.to_char(code_point) }.to_enum
  end
end
Also aliased as: each
each_sentence() { |localize| ... } click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 57
def each_sentence
  if block_given?
    break_iterator.each_sentence(@base_obj) do |sentence|
      yield sentence.localize(locale)
    end
  else
    to_enum(__method__)
  end
end
each_word() { |localize| ... } click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 67
def each_word
  if block_given?
    break_iterator.each_word(@base_obj) do |word|
      yield word.localize(locale)
    end
  else
    to_enum(__method__)
  end
end
hyphenate(delimiter = nil) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 77
def hyphenate(delimiter = nil)
  hyphenated_str = @base_obj.dup

  break_iterator.each_word(@base_obj).reverse_each do |word, start, stop|
    hyphenated_str[start...stop] = hyphenator.hyphenate(word, delimiter)
  end

  hyphenated_str.localize(locale)
end
length()
Alias for: size
normalize(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 23
def normalize(options = {})
  TwitterCldr::Normalization.normalize(@base_obj, options).localize(locale)
end
script() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 160
def script
  TwitterCldr::Utils::ScriptDetector.detect_scripts(@base_obj).best_guess
end
scripts() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 156
def scripts
  TwitterCldr::Utils::ScriptDetector.detect_scripts(@base_obj).scripts
end
size() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 109
def size
  code_points.size
end
Also aliased as: length
titlecase() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 51
def titlecase
  self.class.new(
    TwitterCldr::Shared::Caser.titlecase(@base_obj), locale
  )
end
to_bidi(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 144
def to_bidi(options = {})
  TwitterCldr::Shared::Bidi.from_string(@base_obj, options)
end
to_f(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 99
def to_f(options = {})
  if number_parser.class.is_numeric?(@base_obj)
    number_parser.try_parse(@base_obj, options) do |result|
      result || @base_obj.to_f
    end
  else
    @base_obj.to_f
  end
end
to_i(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 95
def to_i(options = {})
  to_f(options).to_i
end
to_reordered_s(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 148
def to_reordered_s(options = {})
  to_bidi(options).reorder_visually!.to_s
end
to_s() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 91
def to_s
  @base_obj.dup
end
to_territory() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 152
def to_territory
  TwitterCldr::Shared::Territory.new(@base_obj)
end
to_yaml(options = {}) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 140
def to_yaml(options = {})
  TwitterCldr::Utils::YAML.dump(@base_obj, options)
end
transliterate_into(target_locale) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 164
def transliterate_into(target_locale)
  TwitterCldr::Transforms::Transliterator.transliterate(@base_obj, locale, target_locale)
end
upcase() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 45
def upcase
  self.class.new(
    TwitterCldr::Shared::Caser.upcase(@base_obj), locale
  )
end

Private Instance Methods

break_iterator() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 180
def break_iterator
  @break_iterator ||= TwitterCldr::Segmentation::BreakIterator.new(locale)
end
escape_plural_interpolation(string) click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 170
def escape_plural_interpolation(string)
  # escape plural interpolation patterns (see PluralFormatter)
  string.gsub(TwitterCldr::Formatters::PluralFormatter::PLURALIZATION_REGEXP, '%\0')
end
formatter() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 175
def formatter
  @formatter ||=
    TwitterCldr::Formatters::PluralFormatter.for_locale(locale)
end
hyphenator() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 188
def hyphenator
  @hyphenator ||= TwitterCldr::Shared::Hyphenator.get(locale)
end
number_parser() click to toggle source
# File lib/twitter_cldr/localized/localized_string.rb, line 184
def number_parser
  @number_parser ||= TwitterCldr::Parsers::NumberParser.new(locale)
end