Class: TwitterCldr::Localized::LocalizedString

Inherits:
LocalizedObject show all
Includes:
Enumerable
Defined in:
lib/twitter_cldr/localized/localized_string.rb

Instance Attribute Summary

Attributes inherited from LocalizedObject

#base_obj, #locale

Instance Method Summary collapse

Methods inherited from LocalizedObject

#initialize, localize

Constructor Details

This class inherits a constructor from TwitterCldr::Localized::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).



18
19
20
21
# File 'lib/twitter_cldr/localized/localized_string.rb', line 18

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

#[](index) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/twitter_cldr/localized/localized_string.rb', line 82

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

#bytesizeObject



77
78
79
80
# File 'lib/twitter_cldr/localized/localized_string.rb', line 77

def bytesize
  # bytesize method available in ruby 1.9 only
  @base_obj.respond_to?(:bytesize) ? @base_obj.bytesize : @base_obj.size
end

#casefold(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# 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_pointsObject



49
50
51
# File 'lib/twitter_cldr/localized/localized_string.rb', line 49

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

#each_charObject Also known as: each



90
91
92
93
94
95
96
97
98
99
# File 'lib/twitter_cldr/localized/localized_string.rb', line 90

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

#each_sentenceObject



39
40
41
42
43
44
45
46
47
# File 'lib/twitter_cldr/localized/localized_string.rb', line 39

def each_sentence
  if block_given?
    break_iterator.each_sentence(@base_obj) do |sentence|
      yield sentence.localize
    end
  else
    to_enum(__method__)
  end
end

#normalize(options = {}) ⇒ Object



23
24
25
# File 'lib/twitter_cldr/localized/localized_string.rb', line 23

def normalize(options = {})
  TwitterCldr::Normalization.normalize(@base_obj, options).localize(locale)
end

#sizeObject Also known as: length



71
72
73
# File 'lib/twitter_cldr/localized/localized_string.rb', line 71

def size
  code_points.size
end

#to_bidi(options = {}) ⇒ Object



107
108
109
# File 'lib/twitter_cldr/localized/localized_string.rb', line 107

def to_bidi(options = {})
  TwitterCldr::Shared::Bidi.from_string(@base_obj, options)
end

#to_f(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/twitter_cldr/localized/localized_string.rb', line 61

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 = {}) ⇒ Object



57
58
59
# File 'lib/twitter_cldr/localized/localized_string.rb', line 57

def to_i(options = {})
  to_f(options).to_i
end

#to_reordered_s(options = {}) ⇒ Object



111
112
113
# File 'lib/twitter_cldr/localized/localized_string.rb', line 111

def to_reordered_s(options = {})
  to_bidi(options).reorder_visually!.to_s
end

#to_sObject



53
54
55
# File 'lib/twitter_cldr/localized/localized_string.rb', line 53

def to_s
  @base_obj.dup
end

#to_territoryObject



115
116
117
# File 'lib/twitter_cldr/localized/localized_string.rb', line 115

def to_territory
  TwitterCldr::Shared::Territory.new(@base_obj)
end

#to_yaml(options = {}) ⇒ Object



103
104
105
# File 'lib/twitter_cldr/localized/localized_string.rb', line 103

def to_yaml(options = {})
  TwitterCldr::Utils::YAML.dump(@base_obj, options)
end