Class: Cldr::Data::Plurals::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/cldr/data/plurals/rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator = nil, mod = nil, negate = nil, operand = nil) ⇒ Expression

Returns a new instance of Expression.



92
93
94
# File 'lib/cldr/data/plurals/rules.rb', line 92

def initialize(operator = nil, mod = nil, negate = nil, operand = nil)
  @operator, @mod, @negate, @operand = operator, mod, negate, operand
end

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.



90
91
92
# File 'lib/cldr/data/plurals/rules.rb', line 90

def mod
  @mod
end

#negateObject (readonly)

Returns the value of attribute negate.



90
91
92
# File 'lib/cldr/data/plurals/rules.rb', line 90

def negate
  @negate
end

#operandObject (readonly)

Returns the value of attribute operand.



90
91
92
# File 'lib/cldr/data/plurals/rules.rb', line 90

def operand
  @operand
end

#operatorObject (readonly)

Returns the value of attribute operator.



90
91
92
# File 'lib/cldr/data/plurals/rules.rb', line 90

def operator
  @operator
end

Instance Method Details

#to_rubyObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cldr/data/plurals/rules.rb', line 96

def to_ruby
  @ruby ||= begin
    op = 'n'
    op << " % #{@mod}" if mod
    case @operator
    when :is
      op + (@negate ? ' != ' : ' == ') + @operand
    when :in
      (@negate ? '!' : '') + "#{@operand}.include?(#{op})"
    else
      op
    end
  end
end