Files
docuseal/lib/number_utils.rb
T

33 lines
665 B
Ruby
Raw Normal View History

2024-05-12 11:12:07 +03:00
# frozen_string_literal: true
module NumberUtils
FORMAT_LOCALES = {
'dot' => 'de',
'space' => 'fr',
2025-01-17 21:08:13 +02:00
'comma' => 'en',
'usd' => 'en',
'eur' => 'fr',
'gbp' => 'en'
}.freeze
CURRENCY_SYMBOLS = {
'usd' => '$',
'eur' => '€',
'gbp' => '£'
2024-05-12 11:12:07 +03:00
}.freeze
module_function
def format_number(number, format)
locale = FORMAT_LOCALES[format]
2025-01-17 21:08:13 +02:00
if CURRENCY_SYMBOLS[format]
ApplicationController.helpers.number_to_currency(number, locale:, precision: 2, unit: CURRENCY_SYMBOLS[format])
elsif locale
2024-05-12 11:12:07 +03:00
ApplicationController.helpers.number_with_delimiter(number, locale:)
else
number
end
end
end