Skip to content

Commit

Permalink
clean_blank_lines: Add a new function to clean blank Lines
Browse files Browse the repository at this point in the history
This functions removes all blan lines from a block of text e.g

input = ```
foo

bar

foobar
```

output=```
foo
bar
foobar
```
  • Loading branch information
b4ldr committed Jan 18, 2025
1 parent 1fbe9cc commit 7156f7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions/clean_blank_lines.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @summary Remove blank lines from a string
# @param content The content to remove blank lines from
# @return The content with blank lines removed
function extlib::clean_blank_lines (
String[1] $content,
) >> String[1] {
return $content.split("\n").filter |$x| { !$x.empty }.join("\n")
}
20 changes: 20 additions & 0 deletions spec/functions/clean_blank_lines_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'

input = <<-TEXT
string_name: "string_value"
int_name: 42
true_name: yes
TEXT
output = <<-TEXT
string_name: "string_value"
int_name: 42
true_name: yes
TEXT

describe 'extlib::clean_blank_lines' do
it { is_expected.to run.with_params(input).and_return(output) }
end

0 comments on commit 7156f7d

Please sign in to comment.