mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
:sicssors:
This commit is contained in:
parent
d752ae16ab
commit
d7d11f0dab
8 changed files with 2 additions and 15 deletions
|
@ -7,7 +7,6 @@ require 'active_support/core_ext/class/attribute'
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberConverter # :nodoc:
|
||||
|
||||
# Default and i18n option namespace per class
|
||||
class_attribute :namespace
|
||||
|
||||
|
@ -149,9 +148,11 @@ module ActiveSupport
|
|||
def i18n_format_options #:nodoc:
|
||||
locale = opts[:locale]
|
||||
options = I18n.translate(:'number.format', locale: locale, default: {}).dup
|
||||
|
||||
if namespace
|
||||
options.merge!(I18n.translate(:"number.#{namespace}.format", locale: locale, default: {}))
|
||||
end
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
|
@ -172,7 +173,6 @@ module ActiveSupport
|
|||
rescue ArgumentError, TypeError
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToCurrencyConverter < NumberConverter # :nodoc:
|
||||
|
||||
self.namespace = :currency
|
||||
|
||||
def convert
|
||||
|
@ -42,7 +41,6 @@ module ActiveSupport
|
|||
i18n[:negative_format] ||= "-#{i18n[:format]}" if i18n[:format]
|
||||
i18n
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToDelimitedConverter < NumberConverter #:nodoc:
|
||||
|
||||
self.need_valid_float = true
|
||||
|
||||
DELIMITED_REGEX = /(\d)(?=(\d\d\d)+(?!\d))/
|
||||
|
@ -17,7 +16,6 @@ module ActiveSupport
|
|||
left.gsub!(DELIMITED_REGEX) { "#{$1}#{options[:delimiter]}" }
|
||||
[left, right].compact
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToHumanConverter < NumberConverter # :nodoc:
|
||||
|
||||
DECIMAL_UNITS = { 0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion,
|
||||
-1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto }
|
||||
INVERTED_DECIMAL_UNITS = DECIMAL_UNITS.invert
|
||||
|
@ -62,7 +61,6 @@ module ActiveSupport
|
|||
raise ArgumentError, ":units must be a Hash or String translation scope."
|
||||
end.keys.map { |e_name| INVERTED_DECIMAL_UNITS[e_name] }.sort_by { |e| -e }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToHumanSizeConverter < NumberConverter
|
||||
|
||||
STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb]
|
||||
|
||||
self.namespace = :human
|
||||
|
@ -53,7 +52,6 @@ module ActiveSupport
|
|||
def base
|
||||
opts[:prefix] == :si ? 1000 : 1024
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToPercentageConverter < NumberConverter # :nodoc:
|
||||
|
||||
self.namespace = :percentage
|
||||
|
||||
def convert
|
||||
rounded_number = NumberToRoundedConverter.convert(number, options)
|
||||
options[:format].gsub('%n', rounded_number)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,6 @@ module ActiveSupport
|
|||
def phone_ext(ext)
|
||||
ext.blank? ? "" : " x #{ext}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module ActiveSupport
|
||||
module NumberHelper
|
||||
class NumberToRoundedConverter < NumberConverter # :nodoc:
|
||||
|
||||
self.namespace = :precision
|
||||
self.need_valid_float = true
|
||||
|
||||
|
@ -55,7 +54,6 @@ module ActiveSupport
|
|||
number
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue