Class: TwitterCldr::Localized::LocalizedString
Instance Attribute Summary
#base_obj, #locale
Instance Method Summary
collapse
#initialize, localize
Instance Method Details
#%(args) ⇒ Object
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).
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
escape_plural_interpolation(pluralized) % args
end
|
#bytesize ⇒ Object
105
106
107
108
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 105
def bytesize
@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)
options[:t] = [:tr, :az].include?(locale)
end
TwitterCldr::Shared::Casefolder.
casefold(@base_obj, options[:t]).
localize(locale)
end
|
#downcase ⇒ Object
39
40
41
42
43
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 39
def downcase
self.class.new(
TwitterCldr::Shared::Caser.downcase(@base_obj), locale
)
end
|
#each_char ⇒ Object
Also known as:
each
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 118
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_sentence ⇒ Object
57
58
59
60
61
62
63
64
65
|
# 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
end
else
to_enum(__method__)
end
end
|
#each_word ⇒ Object
67
68
69
70
71
72
73
74
75
|
# 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
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
|
#size ⇒ Object
Also known as:
length
99
100
101
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 99
def size
code_points.size
end
|
#titlecase ⇒ Object
51
52
53
54
55
|
# 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 = {}) ⇒ Object
135
136
137
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 135
def to_bidi(options = {})
TwitterCldr::Shared::Bidi.from_string(@base_obj, options)
end
|
#to_f(options = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 89
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
85
86
87
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 85
def to_i(options = {})
to_f(options).to_i
end
|
#to_reordered_s(options = {}) ⇒ Object
139
140
141
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 139
def to_reordered_s(options = {})
to_bidi(options).reorder_visually!.to_s
end
|
#to_s ⇒ Object
81
82
83
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 81
def to_s
@base_obj.dup
end
|
#to_yaml(options = {}) ⇒ Object
131
132
133
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 131
def to_yaml(options = {})
TwitterCldr::Utils::YAML.dump(@base_obj, options)
end
|
#upcase ⇒ Object
45
46
47
48
49
|
# File 'lib/twitter_cldr/localized/localized_string.rb', line 45
def upcase
self.class.new(
TwitterCldr::Shared::Caser.upcase(@base_obj), locale
)
end
|