Class: RandomWords::LoremHTML
- Inherits:
-
Object
- Object
- RandomWords::LoremHTML
- Defined in:
- lib/random-words/lorem_html.rb
Overview
Generates random Lorem Ipsum text in Markdown format.
Instance Attribute Summary collapse
-
#generator ⇒ Object
Stores the RandomWords::Generator.
-
#output ⇒ Object
Stores the output.
-
#title ⇒ Object
readonly
Stores the title.
Instance Method Summary collapse
-
#generate ⇒ String
Use the RandomWords class to generate the Lorem Ipsum text.
-
#initialize(options = {}) ⇒ String
constructor
Generates random Lorem Ipsum text.
Constructor Details
#initialize(options = {}) ⇒ String
Generates random Lorem Ipsum text.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/random-words/lorem_html.rb', line 34 def initialize( = {}) @added = { italic: false, strong: false, link: false, code: false, mark: false, footnote: false, hr: false } defaults = { source: :latin, grafs: 10, sentences: 5, length: :medium, decorate: true, link: false, ul: false, ol: false, dl: false, bq: false, code: false, mark: false, headers: false, table: false, extended: false, footnote: false, hr: false, image: false } = defaults.merge() @generator = RandomWords::Generator.new([:source], { sentence_length: [:length], paragraph_length: [:sentences], use_extended_punctuation: [:extended] }) @title = fragment(2, 5).cap_first @output = '' strong = [:decorate] italic = [:decorate] links = [:link] code = [:code] mark = [:mark] footnotes = [:footnote] [:hr] [:image] force = [] # Generate the specified number of paragraphs. [:grafs].times.with_index do |_, i| if [:grafs] == 1 || i == [:grafs] - 2 force << :footnote if !@added[:footnote] && [:footnote] force << :code if !@added[:code] && [:code] force << :link if !@added[:link] && [:link] force << :italic if !@added[:italic] && [:decorate] force << :strong if !@added[:strong] && [:decorate] end @output += paragraph(1, italic: italic, strong: strong, links: links, code: code, mark: mark, footnotes: footnotes, force: force) italic = Random.rand(0..3).zero? && [:decorate] strong = Random.rand(0..3).zero? && [:decorate] links = Random.rand(0..3).zero? && [:link] code = Random.rand(0..3).zero? && [:code] footnotes = Random.rand(0..3).zero? && [:footnote] @output += "\n\n" end generate end |
Instance Attribute Details
#generator ⇒ Object
Stores the RandomWords::Generator
10 11 12 |
# File 'lib/random-words/lorem_html.rb', line 10 def generator @generator end |
#output ⇒ Object
Stores the output
7 8 9 |
# File 'lib/random-words/lorem_html.rb', line 7 def output @output end |
#title ⇒ Object (readonly)
Stores the title
13 14 15 |
# File 'lib/random-words/lorem_html.rb', line 13 def title @title end |
Instance Method Details
#generate ⇒ String
Use the RandomWords class to generate the Lorem Ipsum text.
112 113 114 115 116 117 118 119 |
# File 'lib/random-words/lorem_html.rb', line 112 def generate compress_newlines handle_lists handle_basic_elements handle_content_blocks finalize_output @output end |