Sha256: ede895a62b6f0a7d2bb09c22588140e4e39e9ccc8cff9312db5aaee19212769d

Contents?: true

Size: 573 Bytes

Versions: 1

Compression:

Stored size: 573 Bytes

Contents

# encoding: utf-8

module TTY
  module Conversion
    class IntegerConverter

      attr_reader :target

      attr_reader :source

      def initialize(source = String)
        @source = source
        @target = Integer
      end

      # @api public
      def convert(value, strict = false)
        Kernel.send(target.name.to_sym, value.to_s)
      rescue
        if strict
          raise InvalidArgument, "#{value} could not be coerced into #{target.name}"
        else
          value.to_i
        end
      end
    end # IntegerConverter
  end # Conversion
end # TTY

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tty-0.1.1 lib/tty/conversion/converter/integer.rb