Sha256: d79942e2cd1ff266155fae466e9af29eac7ceae52788dfe415a75185d2367f6c

Contents?: true

Size: 507 Bytes

Versions: 5

Compression:

Stored size: 507 Bytes

Contents

# frozen_string_literal: true

module InferModel
  class Parsers::Integer
    extend Callable
    extend Dry::Initializer

    param :value
    option :allow_blank, default: -> { true }
    option :base, default: -> { 10 }

    def call
      raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
      return if value.nil? || value.empty?

      Integer(value, base)
    rescue ArgumentError
      raise Parsers::Error, "'#{value}' is not an Integer"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
infer_model-0.1.5 lib/infer_model/parsers/integer.rb
infer_model-0.1.4 lib/infer_model/parsers/integer.rb
infer_model-0.1.2 lib/infer_model/parsers/integer.rb
infer_model-0.1.1 lib/infer_model/parsers/integer.rb
infer_model-0.1.0 lib/infer_model/parsers/integer.rb