ruby-rails-extensions 2.1.0.pre.rc.11 → 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 +19 -0
- 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 +4 -0
- metadata +6 -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,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Array.class_eval do
         | 
| 4 | 
            +
              # Flattens and compacts an array
         | 
| 5 | 
            +
              # @see Array#flatten!
         | 
| 6 | 
            +
              # @see Array#compact!
         | 
| 7 | 
            +
              #
         | 
| 8 | 
            +
              # @return [Array]
         | 
| 9 | 
            +
              #
         | 
| 10 | 
            +
              def flatten_compact!
         | 
| 11 | 
            +
                flatten!
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                compact!
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                self
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              alias_method :flat_pact!, :flatten_compact!
         | 
| 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
         | 
| @@ -25,6 +25,7 @@ module RubyRailsExtensions | |
| 25 25 | 
             
                  find_bang
         | 
| 26 26 | 
             
                  find_dupes
         | 
| 27 27 | 
             
                  first_dupe
         | 
| 28 | 
            +
                  flatten_compact
         | 
| 28 29 | 
             
                  google_format
         | 
| 29 30 | 
             
                  hash_only
         | 
| 30 31 | 
             
                  humanize_symbol
         | 
| @@ -54,11 +55,14 @@ module RubyRailsExtensions | |
| 54 55 | 
             
                  to_bool
         | 
| 55 56 | 
             
                  to_d
         | 
| 56 57 | 
             
                  to_dec
         | 
| 58 | 
            +
                  to_delimited
         | 
| 57 59 | 
             
                  to_i
         | 
| 58 60 | 
             
                  to_local
         | 
| 61 | 
            +
                  to_money
         | 
| 59 62 | 
             
                  to_negative_i
         | 
| 60 63 | 
             
                  to_nonzero_i
         | 
| 61 64 | 
             
                  to_or_sentence
         | 
| 65 | 
            +
                  to_percentage
         | 
| 62 66 | 
             
                  to_positive_i
         | 
| 63 67 | 
             
                  to_sort_i
         | 
| 64 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. | 
| 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:
         | 
| @@ -39,6 +39,7 @@ files: | |
| 39 39 | 
             
            - lib/ruby-rails-extensions/extensions/find_bang.rb
         | 
| 40 40 | 
             
            - lib/ruby-rails-extensions/extensions/find_dupes.rb
         | 
| 41 41 | 
             
            - lib/ruby-rails-extensions/extensions/first_dupe.rb
         | 
| 42 | 
            +
            - lib/ruby-rails-extensions/extensions/flatten_compact.rb
         | 
| 42 43 | 
             
            - lib/ruby-rails-extensions/extensions/google_format.rb
         | 
| 43 44 | 
             
            - lib/ruby-rails-extensions/extensions/hash_only.rb
         | 
| 44 45 | 
             
            - lib/ruby-rails-extensions/extensions/humanize_symbol.rb
         | 
| @@ -68,11 +69,14 @@ files: | |
| 68 69 | 
             
            - lib/ruby-rails-extensions/extensions/to_bool.rb
         | 
| 69 70 | 
             
            - lib/ruby-rails-extensions/extensions/to_d.rb
         | 
| 70 71 | 
             
            - lib/ruby-rails-extensions/extensions/to_dec.rb
         | 
| 72 | 
            +
            - lib/ruby-rails-extensions/extensions/to_delimited.rb
         | 
| 71 73 | 
             
            - lib/ruby-rails-extensions/extensions/to_i.rb
         | 
| 72 74 | 
             
            - lib/ruby-rails-extensions/extensions/to_local.rb
         | 
| 75 | 
            +
            - lib/ruby-rails-extensions/extensions/to_money.rb
         | 
| 73 76 | 
             
            - lib/ruby-rails-extensions/extensions/to_negative_i.rb
         | 
| 74 77 | 
             
            - lib/ruby-rails-extensions/extensions/to_nonzero_i.rb
         | 
| 75 78 | 
             
            - lib/ruby-rails-extensions/extensions/to_or_sentence.rb
         | 
| 79 | 
            +
            - lib/ruby-rails-extensions/extensions/to_percentage.rb
         | 
| 76 80 | 
             
            - lib/ruby-rails-extensions/extensions/to_positive_i.rb
         | 
| 77 81 | 
             
            - lib/ruby-rails-extensions/extensions/to_sort_i.rb
         | 
| 78 82 | 
             
            - lib/ruby-rails-extensions/extensions/to_x.rb
         |