Sha256: 24bf767917652e6b66fa946ca7af314879e9ea47d2ec36c9a498c1e5d9c8e323

Contents?: true

Size: 725 Bytes

Versions: 12

Compression:

Stored size: 725 Bytes

Contents

class Code
  class Node
    class Base10Decimal < Node
      def initialize(number)
        @sign = number[:sign]
        @whole = number.fetch(:whole)
        @decimal = number.fetch(:decimal)

        if number.key?(:exponent)
          @exponent = ::Code::Node::Base10Number.new(number[:exponent])
        end
      end

      def evaluate(**args)
        if @exponent
          exponent = @exponent.evaluate(**args)

          ::Code::Object::Decimal.new(
            "#{sign}#{whole}.#{decimal}",
            exponent: exponent,
          )
        else
          ::Code::Object::Decimal.new("#{sign}#{whole}.#{decimal}")
        end
      end

      private

      attr_reader :sign, :whole, :decimal
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
template-ruby-0.4.0 lib/code/node/base_10_decimal.rb
code-ruby-0.4.0 lib/code/node/base_10_decimal.rb
template-ruby-0.3.1 lib/code/node/base_10_decimal.rb
code-ruby-0.3.1 lib/code/node/base_10_decimal.rb
template-ruby-0.3.0 lib/code/node/base_10_decimal.rb
code-ruby-0.3.0 lib/code/node/base_10_decimal.rb
code-ruby-0.2.4 lib/code/node/base_10_decimal.rb
template-ruby-0.2.4 lib/code/node/base_10_decimal.rb
template-ruby-0.2.3 lib/code/node/base_10_decimal.rb
template-ruby-0.2.2 lib/code/node/base_10_decimal.rb
template-ruby-0.2.1 lib/code/node/base_10_decimal.rb
template-ruby-0.2.0 lib/code/node/base_10_decimal.rb