Class: Jschematic::Attributes::DivisibleBy

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/divisible_by.rb

Instance Attribute Summary

Attributes included from Element

#id, #parent

Instance Method Summary collapse

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

Returns:

  • (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