Class: TwitterCldr::Formatters::Rbnf::RuleFormatter

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.keep_soft_hyphensObject

Returns the value of attribute keep_soft_hyphens.



15
16
17
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 15

def keep_soft_hyphens
  @keep_soft_hyphens
end

Class Method Details

.format(number, rule_set, rule_group, locale) ⇒ Object



17
18
19
20
21
22
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 17

def format(number, rule_set, rule_group, locale)
  rule = rule_set.rule_for(number)
  formatter = formatter_for(rule, rule_set, rule_group, locale)
  result = formatter.format(number, rule)
  keep_soft_hyphens ? result : remove_soft_hyphens(result)
end

.formatter_for(rule, rule_set, rule_group, locale) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb', line 24

def formatter_for(rule, rule_set, rule_group, locale)
  const = case rule.base_value
    when Rule::MASTER
      MasterRuleFormatter
    when Rule::IMPROPER_FRACTION
      ImproperFractionRuleFormatter
    when Rule::PROPER_FRACTION
      ProperFractionRuleFormatter
    when Rule::NEGATIVE
      NegativeRuleFormatter
    else
      NormalRuleFormatter
  end

  const.new(rule_set, rule_group, locale)
end