Class: Restspec::Schema::Types::DecimalType
- Defined in:
- lib/restspec/schema/types/decimal_type.rb
Overview
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)
Direct Known Subclasses
Instance Method Summary collapse
-
#example_for(attribute) ⇒ Object
Generates a random decimal number of 2 digits as integer part and 2 digits as decimal part.
-
#valid?(attribute, value) ⇒ true, false
Validates if the number is a numeric one.
Methods inherited from BasicType
#initialize, #of, #to_s, #totally_valid?, #|
Constructor Details
This class inherits a constructor from Restspec::Schema::Types::BasicType
Instance Method Details
#example_for(attribute) ⇒ Object
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
.
13 14 15 16 17 18 |
# File 'lib/restspec/schema/types/decimal_type.rb', line 13 def example_for(attribute) integer_part = .fetch(:integer_part, 2) decimal_part = .fetch(:decimal_part, 2) Faker::Number.decimal(integer_part, decimal_part).to_f end |
#valid?(attribute, value) ⇒ true, false
Validates if the number is a numeric one.
26 27 28 |
# File 'lib/restspec/schema/types/decimal_type.rb', line 26 def valid?(attribute, value) value.is_a?(Numeric) end |