Mercurial > repos > other > Puppet
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 |
rev | line source |
---|---|
272 | 1 # |
2 # round.rb | |
3 # | |
4 module Puppet::Parser::Functions | |
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 | 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 | 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 | 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 | 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 | 20 DOC |
21 ) do |args| | |
22 | |
23 raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1 | |
24 raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric | |
25 | |
26 value = args[0] | |
27 | |
28 if value >= 0 | |
29 Integer(value + 0.5) | |
30 else | |
31 Integer(value - 0.5) | |
32 end | |
33 end | |
34 end |