Sha256: 143003f2da0cf83e938c4a6dfe5969b8c3eed0fbd838df2ac4e5fab1422c881c

Contents?: true

Size: 474 Bytes

Versions: 2

Compression:

Stored size: 474 Bytes

Contents

module Datev
  class IntegerField < Field
    def limit
      options[:limit]
    end

    def validate!(value)
      super

      if value
        raise ArgumentError.new("Value given for field '#{name}' is not an Integer") unless value.is_a?(Integer)
        raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.to_s.length > limit
      end
    end

    def output(value, _context=nil)
      value.to_s if value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datev-0.4.0 lib/datev/field/integer_field.rb
datev-0.3.1 lib/datev/field/integer_field.rb