lib/cldr-plurals/ruby_emitter.rb in cldr-plurals-1.0.1 vs lib/cldr-plurals/ruby_emitter.rb in cldr-plurals-1.1.0

- old
+ new

@@ -41,11 +41,11 @@ def emit_expression(expr) case expr.value when CldrPlurals::Compiler::Range neg = expr.operation.symbol == '!=' ? '!' : '' - "#{neg}(#{emit_range(expr.value)}).include?(#{emit(expr.operand)})" + "#{neg}(#{emit_range_check(expr.value, expr.operand)})" when CldrPlurals::Compiler::ValueSet "(#{emit_value_set(expr.value, expr.operand, expr.operation)})" else emit_all(expr.operand, expr.operation, expr.value).join(' ') end @@ -54,11 +54,11 @@ def emit_relation(rel) case rel.value when CldrPlurals::Compiler::Range expr = emit(rel.expression) neg = rel.operation.symbol == '!=' ? '!' : '' - "#{neg}(#{emit_range(rel.value)}).include?(#{expr})" + "#{neg}(#{emit_range_check(rel.value, expr)})" when CldrPlurals::Compiler::ValueSet "(#{emit_value_set(rel.value, rel.expression, rel.operation)})" else emit_all(rel.expression, rel.operation, rel.value).join(' ') end @@ -67,11 +67,11 @@ def emit_value_set(value_set, operand, operator) values = value_set.values.map do |value| case value when CldrPlurals::Compiler::Range neg = operator.symbol == '!=' ? '!' : '' - "#{neg}(#{emit_range(value)}).include?(#{emit(operand)})" + "#{neg}(#{emit_range_check(value, operand)})" else "(#{emit(operand)} #{emit(operator)} #{emit(value)})" end end @@ -80,11 +80,13 @@ else values.join(' || ') end end - def emit_range(range) - "#{emit(range.start)}..#{emit(range.finish)}" + def emit_range_check(range, operand) + # a..b represents all *integers* between a and b, inclusive. + n = emit(operand) + "(#{n}.floor == #{n}) && (#{n} >= #{range.start}) && (#{n} <= #{range.finish})" end def emit_operator(op) case op.symbol when '='