Puppet Function: simplib::to_integer

Defined in:
lib/puppet/functions/simplib/to_integer.rb
Function type:
Ruby 4.x API

Overview

simplib::to_integer(Any $input)Integer

Converts the argument into an ‘Integer`.

Terminates catalog compilation if the argument’s class does not respond to the ‘to_i()` Ruby method.

Parameters:

  • input (Any)

    The argument to convert into an ‘Integer`

Returns:

  • (Integer)

    Converted input

Raises:

  • (RuntimeError)

    if “input“ does not implement a “to_i()“ method



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet/functions/simplib/to_integer.rb', line 6

Puppet::Functions.create_function(:'simplib::to_integer') do

  # @param input The argument to convert into an `Integer`
  # @return [Integer] Converted input
  # @raise [RuntimeError] if ``input`` does not implement a ``to_i()``
  #   method
  dispatch :to_integer do
    required_param 'Any', :input
  end

  def to_integer(input)
    return input if input.is_a?(Integer)

    if input.respond_to?(:to_i)
      return input.to_i
    else
      fail("simplib::to_integer(): Object type '#{input.class}' cannot be converted to an Integer")
    end
  end
end