diff --git a/CHANGELOG.md b/CHANGELOG.md index 2057a2f2da..7425303391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Latest update: 2018-05-27 ### Feature Request +- [PR #1064](https://github.com/stympy/faker/pull/1064) Add Faker::Markdown.sandwich [@russellschmidt](https://github.com/russellschmidt) - [PR #1222](https://github.com/stympy/faker/pull/1222) Add paragraph_by_chars functionality [@jguthrie100](https://github.com/jguthrie100) - [PR #1107](https://github.com/stympy/faker/pull/1107) Add tokens to Faker::Stripe [@wecohere](https://github.com/wecohere) - [PR #1258](https://github.com/stympy/faker/pull/1258) Remove simplecov-console and add coverage_report rake task [@vbrazo](https://github.com/vbrazo) diff --git a/doc/markdown.md b/doc/markdown.md index 30679912c4..587ebc46b1 100644 --- a/doc/markdown.md +++ b/doc/markdown.md @@ -28,4 +28,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. ``` diff --git a/lib/faker/markdown.rb b/lib/faker/markdown.rb index ae27f19b43..a2c9160575 100644 --- a/lib/faker/markdown.rb +++ b/lib/faker/markdown.rb @@ -55,6 +55,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 diff --git a/test/test_faker_markdown.rb b/test/test_faker_markdown.rb index f52a7a620e..513b1762d4 100644 --- a/test/test_faker_markdown.rb +++ b/test/test_faker_markdown.rb @@ -71,4 +71,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_instance_of(String, test_array[0]) + assert_instance_of(String, test_array[1]) + assert_instance_of(String, test_array[2]) + end end