Module: TableSchema::Constraints::Minimum

Included in:
TableSchema::Constraints
Defined in:
lib/tableschema/constraints/minimum.rb

Instance Method Summary collapse

Instance Method Details

#check_minimumObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tableschema/constraints/minimum.rb', line 5

def check_minimum
  if @field.type == 'yearmonth'
    valid = Date.new(@value[:year], @value[:month]) >= Date.new(parsed_minimum[:year], parsed_minimum[:month])
  else
    valid = @value >= parsed_minimum
  end

  unless valid
    raise TableSchema::ConstraintError.new("The field `#{@field[:name]}` must not be less than #{@constraints[:minimum]}")
  end
  true
end

#parsed_minimumObject



18
19
20
# File 'lib/tableschema/constraints/minimum.rb', line 18

def parsed_minimum
  @field.cast_type(@constraints[:minimum])
end