Class: Faker::Markdown

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/markdown.rb

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.block_codeObject


43
44
45
# File 'lib/faker/default/markdown.rb', line 43

def block_code
  "```ruby\n#{Lorem.sentence(1)}\n```"
end

.emphasisObject


10
11
12
13
14
15
16
17
# File 'lib/faker/default/markdown.rb', line 10

def emphasis
  paragraph = Faker::Lorem.paragraph(3)
  words = paragraph.split(' ')
  position = rand(0..words.length - 1)
  formatting = fetch('markdown.emphasis')
  words[position] = "#{formatting}#{words[position]}#{formatting}"
  words.join(' ')
end

.headersObject


6
7
8
# File 'lib/faker/default/markdown.rb', line 6

def headers
  "#{fetch('markdown.headers')} #{Lorem.word.capitalize}"
end

.inline_codeObject


39
40
41
# File 'lib/faker/default/markdown.rb', line 39

def inline_code
  "`#{Faker::Lorem.sentence(1)}`"
end

.ordered_listObject


19
20
21
22
23
24
25
26
27
# File 'lib/faker/default/markdown.rb', line 19

def ordered_list
  number = rand(1..10)

  result = []
  number.times do |i|
    result << "#{i}. #{Faker::Lorem.sentence(1)} \n"
  end
  result.join('')
end

.random(*args) ⇒ Object


56
57
58
59
60
# File 'lib/faker/default/markdown.rb', line 56

def random(*args)
  method_list = available_methods
  args&.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
  send(method_list[rand(0..method_list.length - 1)])
end

.sandwich(sentences = 3, repeat = 1) ⇒ Object


62
63
64
65
66
67
68
69
70
# File 'lib/faker/default/markdown.rb', line 62

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

.tableObject


47
48
49
50
51
52
53
54
# File 'lib/faker/default/markdown.rb', line 47

def table
  table = []
  3.times do
    table << "#{Lorem.word} | #{Lorem.word} | #{Lorem.word}"
  end
  table.insert(1, '---- | ---- | ----')
  table.join("\n")
end

.unordered_listObject


29
30
31
32
33
34
35
36
37
# File 'lib/faker/default/markdown.rb', line 29

def unordered_list
  number = rand(1..10)

  result = []
  number.times do |_i|
    result << "* #{Faker::Lorem.sentence(1)} \n"
  end
  result.join('')
end