Class: Faker::Markdown
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.block_code ⇒ String
Produces a random code block formatted in Ruby.
-
.emphasis ⇒ String
Produces a random emphasis formatting on a random word in two sentences.
-
.headers ⇒ String
Produces a random header format.
-
.inline_code ⇒ String
Produces a random inline code snippet between two sentences.
-
.ordered_list ⇒ String
Produces a random ordered list of items between 1 and 10 randomly.
-
.random(methods) ⇒ String+
Produces a random method from the methods above, excluding the methods listed in the arguments.
-
.sandwich(sentences: 3, repeat: 1) ⇒ String
Produces a simulated blog-esque text-heavy block in markdown.
-
.table ⇒ String
Produces a random 3x4 table with a row of headings, a row of hyphens and two rows of data.
-
.unordered_list ⇒ String
Produces a random unordered list of items between 1 and 10 randomly.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.block_code ⇒ String
Produces a random code block formatted in Ruby.
97 98 99 |
# File 'lib/faker/default/markdown.rb', line 97 def block_code "```ruby\n#{Lorem.sentence(word_count: 1)}\n```" end |
.emphasis ⇒ String
Produces a random emphasis formatting on a random word in two sentences.
28 29 30 31 32 33 34 35 |
# File 'lib/faker/default/markdown.rb', line 28 def emphasis paragraph = Faker::Lorem.paragraph(sentence_count: 3) words = paragraph.split position = rand(0..words.length - 1) formatting = fetch('markdown.emphasis') words[position] = "#{formatting}#{words[position]}#{formatting}" words.join(' ') end |
.headers ⇒ String
Produces a random header format.
15 16 17 |
# File 'lib/faker/default/markdown.rb', line 15 def headers "#{fetch('markdown.headers')} #{Lorem.word.capitalize}" end |
.inline_code ⇒ String
Produces a random inline code snippet between two sentences.
84 85 86 |
# File 'lib/faker/default/markdown.rb', line 84 def inline_code "`#{Faker::Lorem.sentence(word_count: 1)}`" end |
.ordered_list ⇒ String
Produces a random ordered list of items between 1 and 10 randomly.
46 47 48 49 50 51 52 53 54 |
# File 'lib/faker/default/markdown.rb', line 46 def ordered_list number = rand(1..10) result = [] number.times do |i| result << "#{i}. #{Faker::Lorem.sentence(word_count: 1)} \n" end result.join end |
.random(methods) ⇒ String+
Produces a random method from the methods above, excluding the methods listed in the arguments.
133 134 135 136 137 |
# File 'lib/faker/default/markdown.rb', line 133 def random(*args) method_list = available_methods args&.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } } send(method_list[Faker::Config.random.rand(0..method_list.length - 1)]) end |
.sandwich(sentences: 3, repeat: 1) ⇒ String
Produces a simulated blog-esque text-heavy block in markdown
Keyword arguments: sentences, repeat
153 154 155 156 157 158 159 160 161 |
# File 'lib/faker/default/markdown.rb', line 153 def sandwich(sentences: 3, repeat: 1) text_block = [] text_block << headers repeat.times do text_block << Faker::Lorem.paragraph(sentence_count: sentences) text_block << random end text_block.join("\n") end |
.table ⇒ String
Produces a random 3x4 table with a row of headings, a row of hyphens and two rows of data
110 111 112 113 114 115 116 117 |
# File 'lib/faker/default/markdown.rb', line 110 def table table = [] 3.times do table << "#{Lorem.word} | #{Lorem.word} | #{Lorem.word}" end table.insert(1, '---- | ---- | ----') table.join("\n") end |
.unordered_list ⇒ String
Produces a random unordered list of items between 1 and 10 randomly.
65 66 67 68 69 70 71 72 73 |
# File 'lib/faker/default/markdown.rb', line 65 def unordered_list number = rand(1..10) result = [] number.times do |_i| result << "* #{Faker::Lorem.sentence(word_count: 1)} \n" end result.join end |