Module: TableSchema::Constraints::Maximum

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

Instance Method Summary collapse

Instance Method Details

#check_maximumObject



5
6
7
8
9
10
11
12
13
14
15
16
# 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_maximumObject



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

def parsed_maximum
  @field.cast_type(@constraints[:maximum])
end