class Restspec::Schema::Types::DecimalType
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)
Public Instance Methods
example_for(attribute)
click to toggle source
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.
# File lib/restspec/schema/types/decimal_type.rb, line 13 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
valid?(attribute, value)
click to toggle source
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
# File lib/restspec/schema/types/decimal_type.rb, line 26 def valid?(attribute, value) value.is_a?(Numeric) end