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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaf63da60d4f5a4025624021d80aa6d5fbc93393f6da419c15207042a503e18f
4
- data.tar.gz: ee1cb13799cf814b9fe027b91ba42f55dd167759d3cad7bb5d463af47bd9e3ba
3
+ metadata.gz: fd0dcbe64c80a08c831af260bb6def15e0a56cb1643b02e9fde7f5904b3b4c37
4
+ data.tar.gz: 37ea13e2a243425c5e5a224005d0c41434532c45ab68b65e6ce4d8f6e7dcea2a
5
5
  SHA512:
6
- metadata.gz: 4f8123053ed9491f33d10815f621ae1e8f5fcc4555a75c44c5cb003467a1bfc6e5a555e56e11f2807ff1df9bf982438557ef39d1587c1436eaf0e3da01b8e758
7
- data.tar.gz: 3c94ad665e2610c2eb3dbeaf21c45ef68cd90a0036d3f3a336ef7de54165583a55e19d214f2878a85ed6f24585e058bdae10892efdab77261a4beef7b9a410b6
6
+ metadata.gz: b2c96c470d791ac8f4ea2dc3b6154a40e24c5bbd56a88375b2f905a5b5803d7bc96601c50e59ad94062c3b54d79d185c45e135b5e3e490230ef342eaa02eda40
7
+ data.tar.gz: '09edbe71001ebad9138c4588333bad479084a96e8094170324330d4ce02fce34fa8d781da8c53877906b3701c95f5afa02d59e5e95f45e9c3aace6e95544f138'
@@ -15,5 +15,5 @@ Array.class_eval do
15
15
  self
16
16
  end
17
17
 
18
- alias flat_pact! flatten_compact!
18
+ alias_method :flat_pact!, :flatten_compact!
19
19
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyRailsExtensions
4
- VERSION = '2.1.0-rc.12'
4
+ VERSION = '2.1.0-rc.13'
5
5
  end
@@ -55,11 +55,14 @@ module RubyRailsExtensions
55
55
  to_bool
56
56
  to_d
57
57
  to_dec
58
+ to_delimited
58
59
  to_i
59
60
  to_local
61
+ to_money
60
62
  to_negative_i
61
63
  to_nonzero_i
62
64
  to_or_sentence
65
+ to_percentage
63
66
  to_positive_i
64
67
  to_sort_i
65
68
  to_x
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.12
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-07 00:00:00.000000000 Z
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