Class: Shogun::Verifier::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/shogun/verifier/range.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, data:, range:) ⇒ Range

Returns a new instance of Range.



4
5
6
7
8
# File 'lib/shogun/verifier/range.rb', line 4

def initialize(name:, data:, range:)
  @data = data
  @name = name
  @range = range
end

Instance Method Details

#contextObject



22
23
24
25
26
27
# File 'lib/shogun/verifier/range.rb', line 22

def context
  {
    "maximum" => @range.max,
    "minimum" => @range.min
  }
end

#idObject



18
19
20
# File 'lib/shogun/verifier/range.rb', line 18

def id
  "#{@name}_was_out_of_range"
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/shogun/verifier/range.rb', line 10

def valid?
  if @data.is_a?(String)
    @range.cover?(@data.size)
  else
    @range.cover?(@data)
  end
end