Sha256: 835311009c4ac58f022d39264d9ea9962be6851e3eb97929ad4c1c73880076c7

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 Bytes

Contents

module FilterParam
  module AST
    module Literals
      class Integer < Literal
        def initialize(value)
          whole_num = value.to_s.split(".").first

          @value = Integer(whole_num)
        rescue ArgumentError
          raise InvalidLiteral.new("Invalid Integer: #{value}")
        end

        def data_type
          :integer
        end

        private

        def to_boolean
          return Literals::Boolean::FALSE if value.zero?

          Literals::Boolean::TRUE
        end

        def to_string
          Literals::String.new(value)
        end

        def to_integer
          self
        end

        def to_decimal
          Literals::Decimal.new(value)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
filter_param-0.1.2 lib/filter_param/ast/literals/integer.rb