Sha256: e9b23a8938d9b433e6a5e18acd5005a25c5e2f629d0647b70b7962131be0e9cb

Contents?: true

Size: 1.17 KB

Versions: 32

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

# Returns the largest `Integer` less or equal to the argument.
# Takes a single numeric value as an argument.
#
# This function is backwards compatible with the same function in stdlib
# and accepts a `Numeric` value. A `String` that can be converted
# to a floating point number can also be used in this version - but this
# is deprecated.
#
# In general convert string input to `Numeric` before calling this function
# to have full control over how the conversion is done.
#
Puppet::Functions.create_function(:floor) do
  dispatch :on_numeric do
    param 'Numeric', :val
  end

  dispatch :on_string do
    param 'String', :val
  end

  def on_numeric(x)
    x.floor
  end

  def on_string(x)
    Puppet.warn_once('deprecations', 'floor_function_numeric_coerce_string',
                     _("The floor() function's auto conversion of String to Float is deprecated - change to convert input before calling"))

    begin
      Float(x).floor
    rescue TypeError, ArgumentError => _e
      # TRANSLATORS: 'floor' is a name and should not be translated
      raise(ArgumentError, _('floor(): cannot convert given value to a floating point value.'))
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/functions/floor.rb
puppet-8.10.0-x86-mingw32 lib/puppet/functions/floor.rb
puppet-8.10.0-x64-mingw32 lib/puppet/functions/floor.rb
puppet-8.10.0-universal-darwin lib/puppet/functions/floor.rb
puppet-8.9.0 lib/puppet/functions/floor.rb
puppet-8.9.0-x86-mingw32 lib/puppet/functions/floor.rb
puppet-8.9.0-x64-mingw32 lib/puppet/functions/floor.rb
puppet-8.9.0-universal-darwin lib/puppet/functions/floor.rb
puppet-8.8.1 lib/puppet/functions/floor.rb
puppet-8.8.1-x86-mingw32 lib/puppet/functions/floor.rb
puppet-8.8.1-x64-mingw32 lib/puppet/functions/floor.rb
puppet-8.8.1-universal-darwin lib/puppet/functions/floor.rb
puppet-8.7.0 lib/puppet/functions/floor.rb
puppet-8.7.0-x86-mingw32 lib/puppet/functions/floor.rb
puppet-8.7.0-x64-mingw32 lib/puppet/functions/floor.rb
puppet-8.7.0-universal-darwin lib/puppet/functions/floor.rb
puppet-8.6.0 lib/puppet/functions/floor.rb
puppet-8.6.0-x86-mingw32 lib/puppet/functions/floor.rb
puppet-8.6.0-x64-mingw32 lib/puppet/functions/floor.rb
puppet-8.6.0-universal-darwin lib/puppet/functions/floor.rb