class TableSchema::Types::Year

Public Class Methods

supported_constraints() click to toggle source
# File lib/tableschema/types/year.rb, line 9
def self.supported_constraints
  [
    'required',
    'unique',
    'enum',
    'minimum',
    'maximum',
  ]
end

Public Instance Methods

cast_default(value) click to toggle source
# File lib/tableschema/types/year.rb, line 23
def cast_default(value)
  cast = ::Date._strptime(value.to_s, '%Y')
  unless cast.nil? || cast.include?(:leftover)
    cast[:year]
  else
    raise TableSchema::InvalidYearType.new("#{value} is not a valid year")
  end
end
name() click to toggle source
# File lib/tableschema/types/year.rb, line 5
def name
  'year'
end
type() click to toggle source
# File lib/tableschema/types/year.rb, line 19
def type
  ::Integer
end