Sha256: a169f281504da8336fb490df9af2c8b57a03afbadd68b0a7e8b5fee5935e431c

Contents?: true

Size: 463 Bytes

Versions: 8

Compression:

Stored size: 463 Bytes

Contents

class RestModel
  module Serialization
    class Integer
      def self.serialize(value)
        case value
        when ::String
          if value =~ /^\d+$/
            value.to_i
          else
            raise
          end
        else
          Integer(value)
        end
      rescue
        raise SerializationError, "value '#{value}' is not an integer"
      end

      def self.desserialize(value)
        serialize(value)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rest_model-0.2.1 lib/rest_model/serialization/integer.rb
rest_model-0.2.0 lib/rest_model/serialization/integer.rb
rest_model-0.1.24 lib/rest_model/serialization/integer.rb
rest_model-0.1.23 lib/rest_model/serialization/integer.rb
rest_model-0.1.22 lib/rest_model/serialization/integer.rb
rest_model-0.1.21 lib/rest_model/serialization/integer.rb
rest_model-0.1.20 lib/rest_model/serialization/integer.rb
rest_model-0.1.19 lib/rest_model/serialization/integer.rb