ruby-rails-extensions 2.1.0.pre.rc.12 → 2.1.0.pre.rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruby-rails-extensions/extensions/flatten_compact.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/to_delimited.rb +36 -0
- data/lib/ruby-rails-extensions/extensions/to_money.rb +20 -0
- data/lib/ruby-rails-extensions/extensions/to_percentage.rb +24 -0
- data/lib/ruby-rails-extensions/version.rb +1 -1
- data/lib/ruby-rails-extensions.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0dcbe64c80a08c831af260bb6def15e0a56cb1643b02e9fde7f5904b3b4c37
|
4
|
+
data.tar.gz: 37ea13e2a243425c5e5a224005d0c41434532c45ab68b65e6ce4d8f6e7dcea2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c96c470d791ac8f4ea2dc3b6154a40e24c5bbd56a88375b2f905a5b5803d7bc96601c50e59ad94062c3b54d79d185c45e135b5e3e490230ef342eaa02eda40
|
7
|
+
data.tar.gz: '09edbe71001ebad9138c4588333bad479084a96e8094170324330d4ce02fce34fa8d781da8c53877906b3701c95f5afa02d59e5e95f45e9c3aace6e95544f138'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/deprecation'
|
5
|
+
require 'active_support/number_helper'
|
6
|
+
require 'bigdecimal'
|
7
|
+
require 'forwardable'
|
8
|
+
|
9
|
+
String.class_eval do
|
10
|
+
include ActiveSupport::NumberHelper
|
11
|
+
|
12
|
+
# Converts a number to a delimited number string
|
13
|
+
# @see ActiveSupport::NumberHelper#number_to_delimited
|
14
|
+
#
|
15
|
+
# @param options [Hash]
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
#
|
19
|
+
def to_delimited(options = {})
|
20
|
+
number_to_delimited(self, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Adding this alias to follow {ActionView::Helpers::NumberHelper#number_with_delimiter}
|
24
|
+
alias_method :with_delimiter, :to_delimited
|
25
|
+
|
26
|
+
# @deprecated This alias is only for Atlas and will be removed in future versions
|
27
|
+
alias_method :with_sep, :to_delimited
|
28
|
+
|
29
|
+
deprecate :with_sep, deprecator: ActiveSupport::Deprecation.new('4.0', 'ruby-rails-extensions')
|
30
|
+
end
|
31
|
+
|
32
|
+
Numeric.class_eval do
|
33
|
+
extend Forwardable
|
34
|
+
|
35
|
+
def_delegators :to_s, :to_delimited, :with_delimiter, :with_sep
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/number_helper'
|
5
|
+
require 'bigdecimal'
|
6
|
+
|
7
|
+
Numeric.class_eval do
|
8
|
+
include ActiveSupport::NumberHelper
|
9
|
+
|
10
|
+
# Converts a number to a money string
|
11
|
+
# @see ActiveSupport::NumberHelper#number_to_currency
|
12
|
+
#
|
13
|
+
# @param options [Hash]
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
#
|
17
|
+
def to_money(options = { precision: 2, negative_format: '%u(%n)' })
|
18
|
+
number_to_currency(to_d, options)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/number_helper'
|
5
|
+
require 'bigdecimal'
|
6
|
+
|
7
|
+
Numeric.class_eval do
|
8
|
+
# Converts an {#Integer}, {#Float}, or {#BigDecimal} into a percentage string.
|
9
|
+
# @see ActiveSupport::NumberHelper#number_to_percentage
|
10
|
+
#
|
11
|
+
# @param options [Hash]
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
#
|
15
|
+
def to_percentage(options = { precision: 2 })
|
16
|
+
num = to_d * 100
|
17
|
+
|
18
|
+
number_to_percentage(num, options)
|
19
|
+
rescue
|
20
|
+
"#{(to_f * 100).round(options.fetch(:precision, 2))}%"
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :to_per, :to_percentage
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-rails-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0.pre.rc.
|
4
|
+
version: 2.1.0.pre.rc.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -69,11 +69,14 @@ files:
|
|
69
69
|
- lib/ruby-rails-extensions/extensions/to_bool.rb
|
70
70
|
- lib/ruby-rails-extensions/extensions/to_d.rb
|
71
71
|
- lib/ruby-rails-extensions/extensions/to_dec.rb
|
72
|
+
- lib/ruby-rails-extensions/extensions/to_delimited.rb
|
72
73
|
- lib/ruby-rails-extensions/extensions/to_i.rb
|
73
74
|
- lib/ruby-rails-extensions/extensions/to_local.rb
|
75
|
+
- lib/ruby-rails-extensions/extensions/to_money.rb
|
74
76
|
- lib/ruby-rails-extensions/extensions/to_negative_i.rb
|
75
77
|
- lib/ruby-rails-extensions/extensions/to_nonzero_i.rb
|
76
78
|
- lib/ruby-rails-extensions/extensions/to_or_sentence.rb
|
79
|
+
- lib/ruby-rails-extensions/extensions/to_percentage.rb
|
77
80
|
- lib/ruby-rails-extensions/extensions/to_positive_i.rb
|
78
81
|
- lib/ruby-rails-extensions/extensions/to_sort_i.rb
|
79
82
|
- lib/ruby-rails-extensions/extensions/to_x.rb
|