Sha256: 3623369d3b68997f0adc9a22eb0aae1198dc520001625c420a0ef3dafb01342d

Contents?: true

Size: 483 Bytes

Versions: 2

Compression:

Stored size: 483 Bytes

Contents

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

    def validate!(value)
      super

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

    def output(value, _context=nil)
      value.slice(0, limit || 255) if value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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