class Gettext::PluralForm::Interpreter
- Gettext::PluralForm::Interpreter
- Gettext::PluralForm::ExpressionVisitor
- Reference
- Object
Overview
A interpreter that calculates the plural-form to take from syntax trees representing the plural-form expression.
Based on this interpreter from crafting interpreters
Defined in:
backend/gettext/plural-forms/interpreter.crConstructors
-
.new(expressions : Array(Expression))
Creates an interpreter with the given expression trees from the
PluralForm::Parser
as input.
Instance Method Summary
-
#interpret(number)
Calculates which plural form to use for the given number
Constructor Detail
def self.new(expressions : Array(Expression))
#
Creates an interpreter with the given expression trees from the PluralForm::Parser
as input.
plural_form_scanner = Gettext::PluralForm::Scanner.new("nplurals=2; plural=(n > 1);")
expressions = Gettext::PluralForm::Parser.new(plural_form_scanner.scan).parse
interpreter = Gettext::PluralForm::Interpreter.new(expressions)
interpreter.interpret(1) # => 0
interpreter.interpret(50) # => 1