Sha256: a181319c186afac972cc111c5aa738bd7fb7d160837e6f33d0944cc1533b1147

Contents?: true

Size: 802 Bytes

Versions: 10

Compression:

Stored size: 802 Bytes

Contents

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

    def maximum
      options[:maximum]
    end

    def minimum
      options[:minimum]
    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
        raise ArgumentError.new("Value '#{value}' for field '#{name}' is too large") if maximum && value > maximum
        raise ArgumentError.new("Value '#{value}' for field '#{name}' is too small") if minimum && value < minimum
      end
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
datev-0.11.0 lib/datev/field/integer_field.rb
datev-0.10.0 lib/datev/field/integer_field.rb
datev-0.9.0 lib/datev/field/integer_field.rb
datev-0.8.2 lib/datev/field/integer_field.rb
datev-0.8.1 lib/datev/field/integer_field.rb
datev-0.8.0 lib/datev/field/integer_field.rb
datev-0.7.0 lib/datev/field/integer_field.rb
datev-0.6.0 lib/datev/field/integer_field.rb
datev-0.5.1 lib/datev/field/integer_field.rb
datev-0.5.0 lib/datev/field/integer_field.rb