Class: Synthra::Types::TextContent::Paragraphs

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/text_content/text_generation.rb

Overview

Paragraphs type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



20
21
22
# File 'lib/synthra/types/text_content/text_generation.rb', line 20

def generate_edge(rng, context, args)
  ["", "A single paragraph."].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



24
25
26
# File 'lib/synthra/types/text_content/text_generation.rb', line 24

def generate_invalid(rng, context, args)
  [nil, 123, [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/synthra/types/text_content/text_generation.rb', line 8

def generate_random(rng, context, args)
  min = args[:min] || 1
  max = args[:max] || 3
  count = rng.int(min, max)
  # English-readable paragraphs — Faker::Hipster reads as English, unlike Latin Lorem.
  Faker::Hipster.paragraphs(number: count).join("\n\n")

rescue StandardError
  "Paragraph 1.\n\nParagraph 2.\n\nParagraph 3."
end