Class: Faker::Markdown

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

Constant Summary

Constants inherited from Base

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

Class Method Summary collapse

Methods inherited from Base

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

Class Method Details

.block_codeObject



41
42
43
# File 'lib/faker/markdown.rb', line 41

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

.emphasisObject



8
9
10
11
12
13
14
15
# File 'lib/faker/markdown.rb', line 8

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



4
5
6
# File 'lib/faker/markdown.rb', line 4

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

.inline_codeObject



37
38
39
# File 'lib/faker/markdown.rb', line 37

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

.ordered_listObject



17
18
19
20
21
22
23
24
25
# File 'lib/faker/markdown.rb', line 17

def ordered_list
  number = rand(1..10)

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

.randomObject



54
55
56
# File 'lib/faker/markdown.rb', line 54

def random
  send(available_methods[rand(0..available_methods.length - 1)])
end

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



58
59
60
61
62
63
64
65
66
# File 'lib/faker/markdown.rb', line 58

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



45
46
47
48
49
50
51
52
# File 'lib/faker/markdown.rb', line 45

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

.unordered_listObject



27
28
29
30
31
32
33
34
35
# File 'lib/faker/markdown.rb', line 27

def unordered_list
  number = rand(1..10)

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