Sha256: 97040e8e23f11dead8ec19f4b9d2c8bfe7d98b7009252dc9494dacf0c6615516

Contents?: true

Size: 1.15 KB

Versions: 50

Compression:

Stored size: 1.15 KB

Contents

#
# size.rb
#

# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...

module Puppet::Parser::Functions
  newfunction(:size, :type => :rvalue, :doc => <<-EOS
Returns the number of elements in a string or array.
    EOS
  ) do |arguments|

    raise(Puppet::ParseError, "size(): Wrong number of arguments " +
      "given (#{arguments.size} for 1)") if arguments.size < 1

    item = arguments[0]

    if item.is_a?(String)

      begin
        #
        # Check whether your item is a numeric value or not ...
        # This will take care about positive and/or negative numbers
        # for both integer and floating-point values ...
        #
        # Please note that Puppet has no notion of hexadecimal
        # nor octal numbers for its DSL at this point in time ...
        #
        Float(item)

        raise(Puppet::ParseError, 'size(): Requires either ' +
          'string or array to work with')

      rescue ArgumentError
        result = item.size
      end

    elsif item.is_a?(Array)
      result = item.size
    else
      raise(Puppet::ParseError, 'size(): Unknown type given')
    end

    return result
  end
end

# vim: set ts=2 sw=2 et :

Version data entries

50 entries across 50 versions & 5 rubygems

Version Path
puppet-retrospec-1.8.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.7.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.6.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.6.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.5.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.4.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.4.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.3.2 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.3.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.3.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.2.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.2.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.1.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-1.0.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.12.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.12.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.11.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.10.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.9.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb
puppet-retrospec-0.9.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/size.rb