Class: Mongomatic::Expectations::IsNumber
- Inherits:
-
Expectation
- Object
- Expectation
- Mongomatic::Expectations::IsNumber
- Defined in:
- lib/mongomatic/expectations/is_number.rb
Instance Attribute Summary
Attributes inherited from Expectation
#instance, #message, #opts, #value
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Expectation
#add_error_msg, define_to_be?, define_to_not_be?, inherited, #initialize
Constructor Details
This class inherits a constructor from Mongomatic::Expectations::Expectation
Class Method Details
.name ⇒ Object
4 5 6 |
# File 'lib/mongomatic/expectations/is_number.rb', line 4 def self.name "a_number" end |
Instance Method Details
#to_be ⇒ Object
8 9 10 11 12 |
# File 'lib/mongomatic/expectations/is_number.rb', line 8 def to_be return true if opts[:allow_nil] && value.nil? add_error_msg if (value.to_s =~ /^\d*\.{0,1}\d+$/).nil? end |
#to_not_be ⇒ Object
14 15 16 |
# File 'lib/mongomatic/expectations/is_number.rb', line 14 def to_not_be add_error_msg unless (value.to_s =~ /^\d*\.{0,1}\d+$/).nil? end |