Sha256: f9445a615d1324d2e0051940a100587ce1a4564c0645224ddbe8fd4e25d6aabb

Contents?: true

Size: 562 Bytes

Versions: 12

Compression:

Stored size: 562 Bytes

Contents

module Datev
  class DecimalField < Field
    def precision
      options[:precision]
    end

    def scale
      options[:scale]
    end

    def validate!(value)
      super

      if value
        raise ArgumentError.new("Value given for field '#{name}' is not a Decimal") unless value.is_a?(Numeric)
        raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if precision && value.to_s.length > precision+1
      end
    end

    def output(value, _context=nil)
      ("%.#{scale}f" % value).sub('.',',') if value
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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