File: range_to_mask.rb

package info (click to toggle)
puppet-module-vswitch 21.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: ruby: 2,189; python: 38; sh: 10; makefile: 10
file content (29 lines) | stat: -rw-r--r-- 598 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# Converts the range to a mask
Puppet::Functions.create_function(:'range_to_mask') do

  dispatch :empty_param do
    param 'Pattern[/^$/]', :range
  end

  dispatch :range_param do
    param 'Pattern[/^[0-9\-\,]/]', :range
  end

  dispatch :undef_param do
    param 'Undef', :range
  end

  def empty_param(range)
    nil
  end

  def undef_param(range)
    nil
  end

  def range_param (range)
    range.to_s.split(",").map{|c| c.include?("-")?(c.split("-").map(&:to_i)[0]..c.split("-").map(&:to_i)[1]).to_a.join(","):c}.join(",").split(",").map{|c| 1<<c.to_i}.inject(0,:|).to_s(16)
  end
end