Class: CldrPlurals::RubyEmitter

Inherits:
Compiler::Emitter show all
Defined in:
lib/cldr-plurals/ruby_emitter.rb

Constant Summary collapse

RUNTIME_VARS =
%w(n i v w f t)

Class Method Summary collapse

Class Method Details

.emit_rule(rule) ⇒ Object



18
19
20
# File 'lib/cldr-plurals/ruby_emitter.rb', line 18

def emit_rule(rule)
  emit(rule.root)
end

.emit_rule_standalone(rule) ⇒ Object



22
23
24
# File 'lib/cldr-plurals/ruby_emitter.rb', line 22

def emit_rule_standalone(rule)
  "lambda { |n, i, f, t, v, w| #{emit_rule(rule)} }"
end

.emit_rules(rule_list) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/cldr-plurals/ruby_emitter.rb', line 9

def emit_rules(rule_list)
  parts = rule_list.rules.map do |rule|
    "(#{emit_rule(rule)} ? :#{rule.name} : "
  end + [':other']

  chooser = "#{parts.join('')}#{')' * (parts.size - 1)}"
  "lambda { |num, runtime| #{build_runtime_vars}; #{chooser} }"
end