Class: Query::Node::Decimal

Inherits:
Query::Node show all
Defined in:
lib/query/node/decimal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ Decimal

Returns a new instance of Decimal.



8
9
10
11
12
13
14
# File 'lib/query/node/decimal.rb', line 8

def initialize(parsed)
  self.decimal = parsed.delete(:decimal)

  if parsed.key?(:exponent)
    self.exponent = Value.new(parsed.delete(:exponent))
  end
end

Instance Attribute Details

#decimalObject

Returns the value of attribute decimal.



6
7
8
# File 'lib/query/node/decimal.rb', line 6

def decimal
  @decimal
end

#exponentObject

Returns the value of attribute exponent.



6
7
8
# File 'lib/query/node/decimal.rb', line 6

def exponent
  @exponent
end

Instance Method Details

#evaluate(**args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/query/node/decimal.rb', line 16

def evaluate(**args)
  if exponent
    BigDecimal(decimal) * 10**exponent.evaluate(**args)
  else
    BigDecimal(decimal)
  end
end