Class: Jschematic::Attributes::ExclusiveMaximum

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/exclusive_maximum.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(enabled, &block) ⇒ ExclusiveMaximum

Returns a new instance of ExclusiveMaximum.



8
9
10
11
12
# File 'lib/jschematic/attributes/exclusive_maximum.rb', line 8

def initialize(enabled, &block)
  @enabled = enabled
  @maximum = block.call("maximum") if block_given?
  raise "'exclusiveMaximum' depends on 'maximum'" unless @maximum
end

Instance Method Details

#accepts?(actual) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/jschematic/attributes/exclusive_maximum.rb', line 14

def accepts?(actual)
  if @enabled
    (actual < @maximum) || fail_validation!("< #{@maximum}", actual)
  end
end