Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Faker::Markdown.sandwich #1064

Merged
merged 8 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ Faker::Markdown.table #=> "ad | similique | voluptatem\n---- | ---- | ----\ncorr

# Random - randomly chooses an above method
Faker::Markdown.random #=> returns output from a single method outlined above

# Sandwich - creates a simulated blog-esque text-heavy block in markdown
Faker::Markdown.sandwich #=> returns newline separated content of 1 header, 1 default lorem paragraph, and 1 random markdown element

Faker::Markdown.sandwich(5) #=> returns newline separated content of 1 header, 1 5-sentence lorem paragraph, and 1 random markdown element

Faker::Markdown.sandwich(6, 3) #=> returns newline separated content of 1 header, and then 3 sections consisting of, here, 1 6-sentence lorem paragraph and 1 random markdown element. The random markdown element is chosen at random in each iteration of the paragraph-markdown pairing.
```
10 changes: 10 additions & 0 deletions lib/faker/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def random
send(available_methods[rand(0..available_methods.length - 1)])
end

def sandwich(sentences = 3, repeat = 1)
text_block = []
text_block << headers
repeat.times do
text_block << Faker::Lorem.paragraph(sentences)
text_block << random
end
text_block.join("\n")
end

private

def available_methods
Expand Down
16 changes: 16 additions & 0 deletions test/test_faker_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ def test_random
assert_instance_of(String, test_trigger)
end

def test_sandwich
test_trigger = @tester.sandwich

test_array = []
test_trigger.each_line{|substr| test_array << substr }

assert(test_array.length == 3)

assert(test_array[0].split(' ').length == 2)
assert(test_array[0].split(' ').first.include?("#"))

assert(test_array[1].count(".") == 3)

assert_instance_of(String, test_array[2])
end

end