Class: CompletionKit::Checks::LengthBounds

Inherits:
Object
  • Object
show all
Defined in:
app/services/completion_kit/checks/length_bounds.rb

Instance Method Summary collapse

Instance Method Details

#call(target, config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/completion_kit/checks/length_bounds.rb', line 4

def call(target, config)
  length = target.to_s.length
  min = config["min"] && config["min"].to_i
  max = config["max"] && config["max"].to_i

  if min && length < min
    Result.new(passed: false, detail: "length #{length} below min #{min}")
  elsif max && length > max
    Result.new(passed: false, detail: "length #{length} above max #{max}")
  else
    Result.new(passed: true, detail: "length #{length} within bounds")
  end
end