Sha256: 96e97ddce084a48acc9503cb04c1f15e35f93887ebc3ddf144d7050bb2d5e2a7

Contents?: true

Size: 828 Bytes

Versions: 164

Compression:

Stored size: 828 Bytes

Contents

module SafeYAML
  class Transform
    class ToInteger
      MATCHERS = Deep.freeze([
        /\A[-+]?(0|([1-9][0-9_,]*))\Z/, # decimal
        /\A0[0-7]+\Z/,                  # octal
        /\A0x[0-9a-f]+\Z/i,             # hexadecimal
        /\A0b[01_]+\Z/                  # binary
      ])

      def transform?(value)
        MATCHERS.each_with_index do |matcher, idx|
          value = value.gsub(/[_,]/, "") if idx == 0
          return true, Integer(value) if matcher.match(value)
        end
        try_edge_cases?(value)
      end

      def try_edge_cases?(value)
        return true, Parse::Hexadecimal.value(value) if Parse::Hexadecimal::MATCHER.match(value)
        return true, Parse::Sexagesimal.value(value) if Parse::Sexagesimal::INTEGER_MATCHER.match(value)
        return false
      end
    end
  end
end

Version data entries

164 entries across 142 versions & 15 rubygems

Version Path
brakeman-4.8.1 bundle/ruby/2.4.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
brakeman-4.8.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/safe_yaml-1.0.4/lib/safe_yaml/transform/to_integer.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.2/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
brakeman-4.7.2 bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/lib/safe_yaml/transform/to_integer.rb