Sha256: 9ea3b5e08c1dc16caba9723a58777469109a4111240df959e1c0d73aa15fabd2

Contents?: true

Size: 750 Bytes

Versions: 3

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

class Code
  class Node
    class Base10 < Node
      def initialize(parsed)
        return if parsed.blank?
        @whole = parsed.delete(:whole).presence

        if parsed.key?(:exponent)
          @exponent = Node::Statement.new(parsed.delete(:exponent).presence)
        end
      end

      def evaluate(**args)
        if @exponent && @whole
          exponent = @exponent.evaluate(**args)
          if exponent.is_a?(Object::Integer)
            Object::Integer.new(@whole, exponent)
          else
            Object::Decimal.new(@whole, exponent)
          end
        elsif @whole
          Object::Integer.new(@whole.to_i)
        else
          Object::Nothing.new
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
code-ruby-0.13.1 lib/code/node/base_10.rb
code-ruby-0.13.0 lib/code/node/base_10.rb
code-ruby-0.12.0 lib/code/node/base_10.rb