Skip to content

Commit 3058e94

Browse files
committed
parameterized prefix removal
1 parent 3b499e3 commit 3058e94

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/puppet_x/lvm/output.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class Output
99
# the data with the prefix removed i.e. "lv_free" would be come "free"
1010
# this however doesn't descriminate and will turn something like
1111
# "foo_bar" into "bar"
12-
def self.parse(key, columns, data)
12+
def self.parse(key, columns, data, prefix2remove = '[A-Za-z]+_')
1313
results = {}
1414

1515
# Remove prefixes
16-
columns = remove_prefixes(columns)
17-
key = remove_prefix(key)
16+
columns = remove_prefixes(columns, prefix2remove)
17+
key = remove_prefix(key, prefix2remove)
1818

1919
data.split("\n").each do |line|
2020
parsed_line = line.gsub(%r{\s+}, ' ').strip.split
@@ -27,14 +27,14 @@ def self.parse(key, columns, data)
2727
results
2828
end
2929

30-
def self.remove_prefixes(array)
30+
def self.remove_prefixes(array, prefix)
3131
array.map do |item|
32-
remove_prefix(item)
32+
remove_prefix(item, prefix)
3333
end
3434
end
3535

36-
def self.remove_prefix(item)
37-
item.gsub(%r{^[A-Za-z]+_}, '')
36+
def self.remove_prefix(item, prefix)
37+
item.gsub(%r{^#{prefix}}, '')
3838
end
3939
end
4040
end

0 commit comments

Comments
 (0)