Class: Datev::DecimalField
- Inherits:
-
Field
- Object
- Field
- Datev::DecimalField
show all
- Defined in:
- lib/datev/field/decimal_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
#output(value, _context = nil) ⇒ Object
20
21
22
|
# File 'lib/datev/field/decimal_field.rb', line 20
def output(value, _context=nil)
("%.#{scale}f" % value).sub('.',',') if value
end
|
#precision ⇒ Object
3
4
5
|
# File 'lib/datev/field/decimal_field.rb', line 3
def precision
options[:precision]
end
|
#scale ⇒ Object
7
8
9
|
# File 'lib/datev/field/decimal_field.rb', line 7
def scale
options[:scale]
end
|
#validate!(value) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/datev/field/decimal_field.rb', line 11
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
|