annotate modules/stdlib/lib/puppet/parser/functions/round.rb @ 275:d9352a684e62

Mass update of modules to remove deprecation warnings
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Jan 2020 11:36:07 +0000
parents c42fb28cff86
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 # round.rb
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 #
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 module Puppet::Parser::Functions
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 newfunction(:round, :type => :rvalue, :doc => <<-DOC
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
6 @summary
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
7 Rounds a number to the nearest integer
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
9 @return
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
10 the rounded value as integer
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
12 @example
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
13
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
14 ```round(2.9)``` returns ```3```
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
16 ```round(2.4)``` returns ```2```
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
18 > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
19 will be used instead of this function.
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 DOC
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 ) do |args|
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 value = args[0]
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 if value >= 0
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 Integer(value + 0.5)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 else
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 Integer(value - 0.5)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 end