Class: Jschematic::Attributes::DivisibleBy
- Inherits:
-
Object
- Object
- Jschematic::Attributes::DivisibleBy
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/divisible_by.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(dividend) ⇒ Boolean
-
#initialize(divisor) ⇒ DivisibleBy
constructor
A new instance of DivisibleBy.
Methods included from Element
#required?, #schema_for, #title, #to_s
Constructor Details
#initialize(divisor) ⇒ DivisibleBy
Returns a new instance of DivisibleBy.
8 9 10 |
# File 'lib/jschematic/attributes/divisible_by.rb', line 8 def initialize(divisor) @divisor = divisor end |
Instance Method Details
#accepts?(dividend) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/jschematic/attributes/divisible_by.rb', line 12 def accepts?(dividend) return true unless Numeric === dividend remainder = (dividend % @divisor) (remainder == 0) || fail_validation!("#{dividend} modulo #{@divisor} to have a remainder of 0", remainder) end |