Class: Hanami::Helpers::NumberFormattingHelper::Formatter Private
- Inherits:
-
Object
- Object
- Hanami::Helpers::NumberFormattingHelper::Formatter
- Defined in:
- lib/hanami/helpers/number_formatting_helper.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Formatter
Constant Summary collapse
- DELIMITATION_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regex to delimitate integer part of a number
/(\d)(?=(\d{3})+$)/.freeze
- INTEGER_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regex to guess if the number is a integer
/\A[\d]+\z/.freeze
- DEFAULT_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default separator
'.'.freeze
- DEFAULT_DELIMITER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default delimiter
','.freeze
- DEFAULT_PRECISION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default precision
2
Instance Method Summary collapse
-
#format ⇒ String
private
Format number according to the specified options.
-
#initialize(number, options) ⇒ Formatter
constructor
private
Initialize a new formatter.
Constructor Details
#initialize(number, options) ⇒ Formatter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new formatter
133 134 135 136 137 138 |
# File 'lib/hanami/helpers/number_formatting_helper.rb', line 133 def initialize(number, ) @number = number @delimiter = .fetch(:delimiter, DEFAULT_DELIMITER) @separator = .fetch(:separator, DEFAULT_SEPARATOR) @precision = .fetch(:precision, nil) end |
Instance Method Details
#format ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format number according to the specified options
148 149 150 |
# File 'lib/hanami/helpers/number_formatting_helper.rb', line 148 def format parts.join(@separator) end |