module TableSchema::Constraints::Maximum

Public Instance Methods

check_maximum() click to toggle source
# File lib/tableschema/constraints/maximum.rb, line 5
def check_maximum
  if @field.type == 'yearmonth'
    valid = Date.new(@value[:year], @value[:month]) <= Date.new(parsed_maximum[:year], parsed_maximum[:month])
  else
    valid = @value <= parsed_maximum
  end

  unless valid
    raise TableSchema::ConstraintError.new("The field `#{@field[:name]}` must not be more than #{@constraints[:maximum]}")
  end
  true
end
parsed_maximum() click to toggle source
# File lib/tableschema/constraints/maximum.rb, line 18
def parsed_maximum
  @field.cast_type(@constraints[:maximum])
end