Class: Datev::StringField

Inherits:
Field
  • Object
show all
Defined in:
lib/datev/field/string_field.rb

Instance Attribute Summary

Attributes inherited from Field

#block, #name, #options

Instance Method Summary collapse

Methods inherited from Field

#initialize, #required?

Constructor Details

This class inherits a constructor from Datev::Field

Instance Method Details

#limitObject



3
4
5
# File 'lib/datev/field/string_field.rb', line 3

def limit
  options[:limit]
end

#output(value, _context = nil) ⇒ Object



16
17
18
19
20
# File 'lib/datev/field/string_field.rb', line 16

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

  quote(value)
end

#validate!(value) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/datev/field/string_field.rb', line 7

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