Class: Terrazzo::Field::Money

Inherits:
Base
  • Object
show all
Defined in:
lib/terrazzo/field/money.rb

Constant Summary

Constants inherited from Base

Base::ABSTRACT_FIELD_CLASSES

Instance Attribute Summary

Attributes inherited from Base

#attribute, #data, #options, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

associative?, default_options, eager_load?, #field_type, #form_input_attributes, #initialize, permitted_attribute, #required?, searchable?, sortable?, transform_param, with_options

Constructor Details

This class inherits a constructor from Terrazzo::Field::Base

Class Method Details

.field_typeObject



27
28
29
# File 'lib/terrazzo/field/money.rb', line 27

def field_type
  "number"
end

Instance Method Details

#serializable_options(page = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/terrazzo/field/money.rb', line 14

def serializable_options(page = nil)
  opts = {}
  opts[:prefix] = options[:prefix] if options.key?(:prefix)
  opts[:suffix] = options[:suffix] if options.key?(:suffix)
  opts[:decimals] = options[:decimals] if options.key?(:decimals)

  # Default to 2 decimal places for currency
  opts[:decimals] ||= 2

  opts
end

#serialize_value(_mode) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/terrazzo/field/money.rb', line 4

def serialize_value(_mode)
  return nil if data.nil?

  if data.respond_to?(:to_f)
    data.to_f
  else
    data
  end
end