module SmartAnswer
  module Question
    class Value < Base
      def initialize(name, options = {}, &block)
        @parse = options[:parse]
        super
      end

      def parse_input(raw_input)
        if Integer == @parse
          begin
            Integer(raw_input)
          rescue TypeError => e
            raise InvalidResponse, e.message
          end
        elsif :to_i == @parse
          raw_input.to_i
        elsif Float == @parse
          begin
            Float(raw_input)
          rescue TypeError => e
            raise InvalidResponse, e.message
          end
        elsif :to_f == @parse
          raw_input.to_f
        else
          super
        end
      end
    end
  end
end

module SmartAnswer
  module Question
    class Value < Base
      def initialize(name, options = {}, &block)
        @parse = options[:parse]
        super
      end

      def parse_input(raw_input)
        if Integer == @parse
          begin
            Integer(raw_input)
          rescue TypeError
            raise InvalidResponse
          end
        elsif :to_i == @parse
          raw_input.to_i
        elsif Float == @parse
          begin
            Float(raw_input)
          rescue TypeError
            raise InvalidResponse
          end
        elsif :to_f == @parse
          raw_input.to_f
        else
          super
        end
      end
    end
  end
end

Remove unused and therefore confusing exception message
Remove unused and therefore confusing exception message

As discussed here [1], the exception message is only ever used as a key to
**lookup** an error message from the locale files.

Looking at the original code [2] which motivated the introduction of this
`rescue` clause, it was simply raising an `InvalidResponse` exception
without explicitly setting a message.

So I've now changed the code so it no longer sets a message on the
`InvalidResponse` exception - this means the code is as similar as possible to
the original.

Note that this commit has not changed the behaviour visible to users, because
there is no key with the name: `:"can't convert nil into Integer"` in the
locale files.

[1]: https://github.com/alphagov/smart-answers/commit/d7b66ed91bc0cb5334a0de1884787c61a0d5cc01#commitcomment-11361001
[2]: 28785dd848d206e80e82c6c147b0db719258862a
