Class: DemoLorem::Generator
- Inherits:
-
Object
- Object
- DemoLorem::Generator
- Defined in:
- lib/demo_lorem/generator.rb
Constant Summary collapse
- LATIN_WORDS =
%w[ Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum ]- CICERO_WORDS =
%w[ But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness ]- PANGRAM_WORDS =
%w[ The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt fox ]
Instance Method Summary collapse
-
#generate_text(topic:, length: nil, api_based_on: nil, api_key: nil) ⇒ Object
Generates text based on user input.
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
Methods included from Helpers::NonaiApiHelper
Methods included from Helpers::AiApiHelper
Methods included from Helpers::RegexHelper
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
53 54 55 56 |
# File 'lib/demo_lorem/generator.rb', line 53 def initialize( = {}) @default_length = [:default_length] || 100 @debug = [:debug] || false end |
Instance Method Details
#generate_text(topic:, length: nil, api_based_on: nil, api_key: nil) ⇒ Object
Generates text based on user input
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/demo_lorem/generator.rb', line 59 def generate_text(topic:, length: nil, api_based_on: nil, api_key: nil) content_generators = { 'default' => ->(l) { ipsum(l) }, 'cicero' => ->(l) { cicero(l) }, 'pangram' => ->(l) { pangram(l) }, 'random_regex' => ->(_) { random_regex } } generator = content_generators[topic] || ->(l) { fetch_api_content(topic, l, api_based_on, api_key) } generator.call(length) end |