Sha256: 52bf143a891b64d23a37ebb3e9337c9638c7148c75c53a3ea9c80e775d8c33f9
Contents?: true
Size: 1.17 KB
Versions: 11
Compression:
Stored size: 1.17 KB
Contents
module Restspec::Schema::Types # Represents a decimal number. It has the following options: # - example_options: # - integer_part: The integer part precision of the generated decimal. (Default: 2) # - decimal_part: The decimal part precision of the generated decimal. (Default: 2) class DecimalType < BasicType # Generates a random decimal number of 2 digits as integer part # and 2 digits as decimal part. Both can be overrided using the # example options `integer_part` and `decimal_part`. # # @param attribute [Restspec::Schema::Attribute] the atribute of the schema. # @return A random decimal number. def example_for(attribute) integer_part = example_options.fetch(:integer_part, 2) decimal_part = example_options.fetch(:decimal_part, 2) Faker::Number.decimal(integer_part, decimal_part).to_f end # Validates if the number is a numeric one. # # @param attribute [Restspec::Schema::Attribute] the atribute of the schema. # @param value [Object] the value of the attribute. # # @return [true, false] If the value is a number def valid?(attribute, value) value.is_a?(Numeric) end end end
Version data entries
11 entries across 11 versions & 1 rubygems