Class: TwitterCldr::Formatters::Rbnf::MasterRuleFormatter

Inherits:
NormalRuleFormatter show all
Defined in:
lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb

Instance Attribute Summary

Attributes inherited from NormalRuleFormatter

#is_fractional, #locale, #omit, #rule_group, #rule_set

Instance Method Summary collapse

Methods inherited from NormalRuleFormatter

#decimal, #equals, #format, #generate_replacement, #initialize, #plaintext, #plural, #semicolon

Constructor Details

This class inherits a constructor from TwitterCldr::Formatters::Rbnf::NormalRuleFormatter

Instance Method Details

#close_bracket(number, rule, token) ⇒ Object



207
208
209
210
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 207

def close_bracket(number, rule, token)
  @omit = false
  ""
end

#left_arrow(number, rule, token) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 184

def left_arrow(number, rule, token)
  if is_fractional
    # is this necessary?
    RuleFormatter.format(
      (number * fractional_rule(number).base_value).to_i,
      rule_set, rule_group, locale
    )
  else
    generate_replacement(integral_part(number), rule, token)
  end
end

#open_bracket(number, rule, token) ⇒ Object



196
197
198
199
200
201
202
203
204
205
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 196

def open_bracket(number, rule, token)
  @omit = if is_fractional
    # is this necessary?
    (number * fractional_rule(number).base_value) == 1
  else
    # Omit the optional text if the number is an integer (same as specifying both an x.x rule and an x.0 rule)
    @omit = number.is_a?(Integer)
  end
  ""
end

#right_arrow(number, rule, token) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 172

def right_arrow(number, rule, token)
  # Format by digits. This is not explained in the main doc. See:
  # http://grepcode.com/file/repo1.maven.org/maven2/com.ibm.icu/icu4j/51.2/com/ibm/icu/text/NFSubstitution.java#FractionalPartSubstitution.%3Cinit%3E%28int%2Ccom.ibm.icu.text.NFRuleSet%2Ccom.ibm.icu.text.RuleBasedNumberFormat%2Cjava.lang.String%29

  # doesn't seem to matter if the descriptor is two or three arrows, although three seems to indicate
  # we should or should not be inserting spaces somewhere (not sure where)
  is_fractional = true
  number.to_s.split(".")[1].each_char.map do |digit|
    RuleFormatter.format(digit.to_i, rule_set, rule_group, locale)
  end.join(" ")
end