demo_lorem 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +138 -13
- data/demo_lorem.gemspec +37 -14
- data/lib/demo_lorem/generator.rb +97 -0
- data/lib/demo_lorem/helpers/ai_api_helper.rb +32 -0
- data/lib/demo_lorem/helpers/nonai_api_helper.rb +36 -0
- data/lib/demo_lorem/helpers/regex_helper.rb +21 -0
- data/lib/demo_lorem/version.rb +1 -1
- data/lib/demo_lorem.rb +10 -4
- data/spec/demo_lorem/generator_spec.rb +91 -0
- metadata +132 -31
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cec1a39cdb215b819003cbdf5ca665fef53fdf961617762bc6a392923e1af9cc
|
4
|
+
data.tar.gz: 5cac3eafba4438c082da02fee6bad4fbb0559d6c26d89d2deca2ae6cb5d44ad0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c70aeb14b531fa9d1c793e5adbbc04342d33d2095f286538dda5d05554616588ee17ad6ce32402db675b60cb1a1b1d1c5e90691b02154456b09f40309bdd24aa
|
7
|
+
data.tar.gz: 1176f1880feac5ccc4c45b094a10c2bcaced976a2ad1ebaa26b4e1afd5fc5f2094a725a8005ae5aa6e730c946db6d8ddf1ffc969e0124a8a203a4ed4b6597b3d
|
data/README.md
CHANGED
@@ -1,29 +1,154 @@
|
|
1
1
|
# DemoLorem
|
2
2
|
|
3
|
-
|
3
|
+
DemoLorem is a versatile text generation gem that provides multiple methods for generating placeholder text, ranging from traditional Lorem Ipsum to AI-powered content generation.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
- **Traditional Lorem Ipsum**: Classic placeholder text generation
|
7
|
+
- **Cicero Text**: Historical text based on Cicero's writings
|
8
|
+
- **Pangram Text**: Text containing every letter of the alphabet
|
9
|
+
- **Random Regex**: Generate random regular expressions for testing
|
10
|
+
- **AI-Powered Content**: Generate topic-specific content using OpenAI
|
11
|
+
- **Wikipedia Content**: Fetch real-world content from Wikipedia
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
7
15
|
Add this line to your application's Gemfile:
|
16
|
+
```ruby
|
17
|
+
gem 'demo_lorem'
|
18
|
+
```
|
19
|
+
Or install directly as:
|
20
|
+
```
|
21
|
+
gem install demo_lorem
|
22
|
+
```
|
8
23
|
|
9
|
-
|
24
|
+
## Usage
|
10
25
|
|
11
|
-
|
26
|
+
Basic Text Generation:
|
27
|
+
```ruby
|
28
|
+
generator = DemoLorem::Generator.new
|
12
29
|
|
13
|
-
|
30
|
+
# Generate Lorem Ipsum
|
31
|
+
generator.generate_text(topic: 'default', length: 100)
|
14
32
|
|
15
|
-
|
33
|
+
# Generate Cicero text
|
34
|
+
generator.generate_text(topic: 'cicero', length: 100)
|
16
35
|
|
17
|
-
|
36
|
+
# Generate Pangram text
|
37
|
+
generator.generate_text(topic: 'pangram', length: 100)
|
38
|
+
```
|
18
39
|
|
19
|
-
|
40
|
+
Random Regex Generation:
|
41
|
+
```ruby
|
42
|
+
# Generate random regular expression pattern
|
43
|
+
generator.generate_text(topic: 'random_regex')
|
44
|
+
# => Returns a Regexp object for testing pattern matching
|
45
|
+
|
46
|
+
# Example usage
|
47
|
+
sample_strings = ["Hello World!", "abc123", "This is a test string.", "Another_example_456"]
|
48
|
+
sample_strings.each do |string|
|
49
|
+
match = string.match(random_regex)
|
50
|
+
puts "#{string} matches pattern? #{!match.nil?}"
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
AI-Powered Content Generation:
|
55
|
+
```ruby
|
56
|
+
# Generate AI content about a specific topic
|
57
|
+
generator.generate_text(
|
58
|
+
topic: 'artificial intelligence',
|
59
|
+
length: 200,
|
60
|
+
api_based_on: 'ai',
|
61
|
+
api_key: 'your_openai_api_key'
|
62
|
+
)
|
63
|
+
```
|
64
|
+
|
65
|
+
Wikipedia Content Fetching:
|
66
|
+
```ruby
|
67
|
+
# Fetch Wikipedia content for a specific topic
|
68
|
+
generator.generate_text(
|
69
|
+
topic: 'Ruby (programming language)',
|
70
|
+
length: 100,
|
71
|
+
api_based_on: 'wikipedia'
|
72
|
+
)
|
73
|
+
```
|
74
|
+
|
75
|
+
## Possible Use Cases:
|
76
|
+
- **Development Testing**:
|
77
|
+
- Generate placeholder text for UI development/testing purposes
|
78
|
+
- Test data generation
|
79
|
+
- Form field population
|
80
|
+
- **Content Generation**:
|
81
|
+
- Quick content prototyping
|
82
|
+
- Sample texts for layouts
|
83
|
+
- Draft content templates for various topics
|
84
|
+
- **Testing Regular Expressions**:
|
85
|
+
- Generate test pattern
|
86
|
+
- Validate regex implementations
|
87
|
+
- Pattern matching scenarios
|
88
|
+
- **Educational Content**:
|
89
|
+
- Generate topic-specific learning materials
|
90
|
+
- Create practice content
|
91
|
+
- Sample data for tutorials
|
92
|
+
|
93
|
+
## Configuration
|
94
|
+
Initialize the custom options:
|
95
|
+
```ruby
|
96
|
+
generator = DemoLorem::Generator.new(
|
97
|
+
default_length: 150, # Default text length
|
98
|
+
debug: true # Enable debug output
|
99
|
+
)
|
100
|
+
```
|
101
|
+
## Detailed Sections:
|
102
|
+
### 1 Random Regex:
|
103
|
+
Signficance:
|
104
|
+
- Development Testing: Generate dynamic test patterns for input validation and form testing
|
105
|
+
- Pattern Matching: Create random regex patterns to validate text processing functionality
|
106
|
+
- Test Data: Generate test cases for regex-based search and replace operations
|
107
|
+
### 2 AI-Powered Content Generation:
|
108
|
+
Signficance:
|
109
|
+
- Topic-Specific Content: Generate relevant content about any subject using OpenAI's GPT model
|
110
|
+
- Customizable Length: Control content length for different use cases (snippets to full articles)
|
111
|
+
- Dynamic Content: Create unique, contextual content for prototypes and demonstrations
|
112
|
+
- Error Handling: Robust error management for API issues and rate limiting
|
113
|
+
### 3 Wikipedia Content:
|
114
|
+
Signficance:
|
115
|
+
- Real-World Content: Fetch factual content from Wikipedia for authentic text samples
|
116
|
+
- Multiple Variations: Smart handling of topic variations for better content matching
|
117
|
+
- Fallback Mechanism: Graceful handling when content isn't available
|
118
|
+
- Length Control: Specify exact character length for content snippets
|
119
|
+
## Requirements
|
120
|
+
- Ruby >= 2.6.0
|
121
|
+
- OpenAI API key (for AI-powered generation)
|
122
|
+
- Internet connection (for Wikipedia content)
|
123
|
+
## Future Enhancements
|
124
|
+
May add few more methods in future(hopefully soon "[:)]" ).
|
125
|
+
## Update
|
126
|
+
We've made some significant updates to DemoLorem. Here are the highlights:
|
127
|
+
|
128
|
+
- Removed Methods: We've streamlined the gem by removing some methods that were required for specific personal projects but no longer serve a general purpose.
|
129
|
+
These include:
|
20
130
|
|
21
|
-
|
131
|
+
- weather
|
132
|
+
|
133
|
+
- kafka
|
134
|
+
|
135
|
+
- european_languages
|
136
|
+
|
137
|
+
- far_far_away
|
138
|
+
|
139
|
+
- New Methods: To enhance functionality, we've added two new powerful methods:
|
140
|
+
|
141
|
+
- AI-Based Content Generation: Fetches content from AI sources like OpenAI, allowing for more dynamic and topic-specific text generation.
|
142
|
+
|
143
|
+
- Non-AI Content Fetching: Fetches content from non-AI sources such as Wikipedia, providing real-world content for your applications.
|
144
|
+
|
145
|
+
- Modified random_regex Method: The random_regex method has been improved to generate more diverse and complex regular expressions, useful for testing and development purposes.
|
146
|
+
|
147
|
+
These updates are designed to provide more flexibility and functionality, enhancing your ability to generate and fetch content as per your needs.
|
22
148
|
|
23
149
|
## Contributing
|
24
150
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
5. Create new Pull Request
|
151
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Manmohan-menon/demo_lorem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the basic code of conduct..
|
152
|
+
|
153
|
+
## License
|
154
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/demo_lorem.gemspec
CHANGED
@@ -1,23 +1,46 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path('
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
4
5
|
require 'demo_lorem/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'demo_lorem'
|
8
9
|
spec.version = DemoLorem::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
10
|
+
spec.authors = ['Manmohan-menon']
|
11
|
+
spec.email = ['manmohan.menon@gmail.com']
|
12
|
+
spec.description = 'Lorem Ipsum generator'
|
13
|
+
spec.summary = 'A dummy text generator like lorem ipsum or some user specific topic'
|
14
|
+
spec.homepage = 'https://github.com/Manmohan-menon/demo_lorem'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.6.0'
|
18
|
+
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/Manmohan-menon/demo_lorem'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/Manmohan-menon/demo_lorem'
|
23
|
+
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
Dir[
|
26
|
+
'lib/**/*.rb',
|
27
|
+
'lib/demo_lorem/helpers/*.rb',
|
28
|
+
'README.md',
|
29
|
+
'demo_lorem.gemspec'
|
30
|
+
].reject { |file| file == 'demo_lorem-0.0.4.gem' }
|
31
|
+
end
|
32
|
+
spec.bindir = 'exe'
|
33
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
34
|
+
spec.test_files = Dir['spec/**/*_spec.rb']
|
35
|
+
spec.require_paths = ['lib']
|
15
36
|
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.
|
19
|
-
spec.
|
37
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
38
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
40
|
+
spec.add_development_dependency 'webmock', '~> 3.18'
|
20
41
|
|
21
|
-
spec.
|
22
|
-
spec.
|
42
|
+
spec.add_runtime_dependency 'cgi', '~> 0.1', '>= 0.1.0'
|
43
|
+
spec.add_runtime_dependency 'httparty', '~> 0.18', '>= 0.18.1'
|
44
|
+
spec.add_dependency 'json', '~> 2.6'
|
45
|
+
spec.add_runtime_dependency 'openai', '~> 0.1', '>= 0.1.0'
|
23
46
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# DemoLorem Generator
|
4
|
+
#
|
5
|
+
# Provides text generation capabilities through various methods:
|
6
|
+
# - Traditional Lorem Ipsum
|
7
|
+
# - Cicero-style phrases
|
8
|
+
# - Pangrams
|
9
|
+
# - Random Regex generation
|
10
|
+
# - AI-powered content generation
|
11
|
+
# - Wikipedia content fetching
|
12
|
+
#
|
13
|
+
# Usage:
|
14
|
+
# generator = DemoLorem::Generator.new(default_length: 200)
|
15
|
+
# generated_text = generator.generate_text(topic: 'default', length: 150)
|
16
|
+
|
17
|
+
require 'net/http'
|
18
|
+
require 'json'
|
19
|
+
require 'cgi'
|
20
|
+
require 'httparty'
|
21
|
+
require 'openai'
|
22
|
+
require_relative 'helpers/regex_helper'
|
23
|
+
require_relative 'helpers/ai_api_helper'
|
24
|
+
require_relative 'helpers/nonai_api_helper'
|
25
|
+
|
26
|
+
module DemoLorem
|
27
|
+
class Generator
|
28
|
+
include Helpers::RegexHelper
|
29
|
+
include Helpers::AiApiHelper
|
30
|
+
include Helpers::NonaiApiHelper
|
31
|
+
|
32
|
+
LATIN_WORDS = %w[
|
33
|
+
Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod
|
34
|
+
tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam
|
35
|
+
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
36
|
+
consequat Duis aute irure dolor in reprehenderit in voluptate velit esse
|
37
|
+
cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non
|
38
|
+
proident sunt in culpa qui officia deserunt mollit anim id est laborum
|
39
|
+
]
|
40
|
+
|
41
|
+
CICERO_WORDS = %w[
|
42
|
+
But I must explain to you how all this mistaken idea of denouncing pleasure and praising
|
43
|
+
pain was born and I will give you a complete account of the system, and expound the actual
|
44
|
+
teachings of the great explorer of the truth, the master-builder of human happiness
|
45
|
+
]
|
46
|
+
|
47
|
+
PANGRAM_WORDS = %w[
|
48
|
+
The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced
|
49
|
+
by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs
|
50
|
+
grab quick-jived waltz. Brick quiz whangs jumpy veldt fox
|
51
|
+
]
|
52
|
+
|
53
|
+
def initialize(options = {})
|
54
|
+
@default_length = options[:default_length] || 100
|
55
|
+
@debug = options[:debug] || false
|
56
|
+
end
|
57
|
+
|
58
|
+
# Generates text based on user input
|
59
|
+
def generate_text(topic:, length: nil, api_based_on: nil, api_key: nil)
|
60
|
+
content_generators = {
|
61
|
+
'default' => ->(l) { ipsum(l) },
|
62
|
+
'cicero' => ->(l) { cicero(l) },
|
63
|
+
'pangram' => ->(l) { pangram(l) },
|
64
|
+
'random_regex' => ->(_) { random_regex }
|
65
|
+
}
|
66
|
+
|
67
|
+
generator = content_generators[topic] || ->(l) { fetch_api_content(topic, l, api_based_on, api_key) }
|
68
|
+
generator.call(length)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def ipsum(word_count = 100)
|
74
|
+
LATIN_WORDS.sample(word_count).join(' ') + '.'
|
75
|
+
end
|
76
|
+
|
77
|
+
def cicero(word_count = 100)
|
78
|
+
CICERO_WORDS.sample(word_count).join(' ') + '.'
|
79
|
+
end
|
80
|
+
|
81
|
+
def pangram(word_count = 100)
|
82
|
+
PANGRAM_WORDS.sample(word_count).join(' ') + '.'
|
83
|
+
end
|
84
|
+
|
85
|
+
def fetch_api_content(topic, length, api_based_on, api_key)
|
86
|
+
if api_based_on == 'ai'
|
87
|
+
fetch_ai_content(topic, length, api_key)
|
88
|
+
else
|
89
|
+
fetch_wikipedia_content(topic, length)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def debug_output(message)
|
94
|
+
puts "[Debug] #{message}" if @debug
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openai'
|
4
|
+
|
5
|
+
module DemoLorem
|
6
|
+
module Helpers
|
7
|
+
# AiApiHelper module fetches AI-generated content using OpenAI's API for a given topic and length
|
8
|
+
# @param topic [String] the topic to generate content for.
|
9
|
+
# @param length [Integer] the number of characters to generate.
|
10
|
+
# @param api_key [String] the API key for accessing OpenAI's API.
|
11
|
+
# @return [String] the content generated by OpenAI.
|
12
|
+
module AiApiHelper
|
13
|
+
def fetch_ai_content(topic, length, api_key)
|
14
|
+
return 'OpenAI API key is required for AI-based generation' if api_key.nil?
|
15
|
+
|
16
|
+
begin
|
17
|
+
client = OpenAI::Client.new(access_token: api_key)
|
18
|
+
response = client.completions(
|
19
|
+
parameters: {
|
20
|
+
model: 'text-davinci-003',
|
21
|
+
prompt: "Generate #{length} characters of text about #{topic}",
|
22
|
+
max_tokens: length
|
23
|
+
}
|
24
|
+
)
|
25
|
+
response['choices'].first['text'].strip
|
26
|
+
rescue StandardError => e
|
27
|
+
"An error occurred while fetching AI content: #{e.message}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'cgi'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module DemoLorem
|
8
|
+
module Helpers
|
9
|
+
# NonaiApiHelper module currently fetches wikipedia content for a given topic and length
|
10
|
+
# @param topic [String] the topic to search for
|
11
|
+
# @param length [Integer] the number of characters to fetch
|
12
|
+
# @return [String] content fetched from Wikipedias
|
13
|
+
module NonaiApiHelper
|
14
|
+
def fetch_wikipedia_content(topic, length)
|
15
|
+
puts 'Please wait while we fetch your content... (this may take 2-10 seconds)'
|
16
|
+
sleep(rand(2..10)) # Simulate wait time
|
17
|
+
|
18
|
+
variations = [topic, topic.tr('_', ' ')]
|
19
|
+
variations.each do |variation|
|
20
|
+
url = "https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exchars=#{length}&explaintext=true&format=json&titles=#{CGI.escape(variation)}"
|
21
|
+
response = HTTParty.get(url)
|
22
|
+
pages = response.dig('query', 'pages')
|
23
|
+
next if pages.nil? || pages.empty?
|
24
|
+
|
25
|
+
page = pages.values.first
|
26
|
+
extract = page.dig('extract')
|
27
|
+
return extract unless extract.nil? || extract.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
'No content found for the given topic'
|
31
|
+
rescue StandardError => e
|
32
|
+
"An error occurred while fetching Wikipedia content: #{e.message}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DemoLorem
|
4
|
+
module Helpers
|
5
|
+
# RegexHelper module generates random regular expressions
|
6
|
+
module RegexHelper
|
7
|
+
def random_regex
|
8
|
+
characters = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
9
|
+
metacharacters = %w[. * + ?]
|
10
|
+
quantifiers = %w[{1,3} {2,5} + *]
|
11
|
+
character_classes = ['[a-z]', '[A-Z]', '[0-9]', '\w', '\d']
|
12
|
+
base_pattern = characters.sample(5).join
|
13
|
+
base_pattern = "#{character_classes.sample}#{base_pattern}"
|
14
|
+
base_pattern = "#{base_pattern}#{metacharacters.sample}#{quantifiers.sample}"
|
15
|
+
full_pattern = "(#{base_pattern})"
|
16
|
+
|
17
|
+
Regexp.new(full_pattern)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/demo_lorem/version.rb
CHANGED
data/lib/demo_lorem.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "demo_lorem/version"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
require "cgi"
|
7
|
+
require "httparty"
|
8
|
+
require "openai"
|
9
|
+
require_relative "demo_lorem/generator"
|
2
10
|
|
3
11
|
module DemoLorem
|
4
|
-
|
5
|
-
"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."
|
6
|
-
end
|
12
|
+
class Error < StandardError; end
|
7
13
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'demo_lorem'
|
3
|
+
|
4
|
+
RSpec.describe DemoLorem::Generator do
|
5
|
+
let(:generator) { described_class.new }
|
6
|
+
let(:generator_with_options) { described_class.new(default_length: 50, debug: true) }
|
7
|
+
let(:api_key) { ENV['OPENAI_API_KEY'] || 'dummy_api_key_for_testing' }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
it 'creates a new generator with default options' do
|
11
|
+
expect(generator).to be_a(DemoLorem::Generator)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a new generator with custom options' do
|
15
|
+
expect(generator_with_options).to be_a(DemoLorem::Generator)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#generate_text' do
|
20
|
+
context 'with default lorem ipsum' do
|
21
|
+
it 'generates lorem ipsum text' do
|
22
|
+
result = generator.generate_text(topic: 'default', length: 100)
|
23
|
+
expect(result).to be_a(String)
|
24
|
+
expect(result).to end_with('.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with cicero text' do
|
29
|
+
it 'generates cicero text' do
|
30
|
+
result = generator.generate_text(topic: 'cicero', length: 100)
|
31
|
+
expect(result).to be_a(String)
|
32
|
+
expect(result).to end_with('.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with pangram text' do
|
37
|
+
it 'generates pangram text' do
|
38
|
+
result = generator.generate_text(topic: 'pangram', length: 100)
|
39
|
+
expect(result).to be_a(String)
|
40
|
+
expect(result).to end_with('.')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with random regex' do
|
45
|
+
it 'generates a valid regex pattern' do
|
46
|
+
result = generator.generate_text(topic: 'random_regex')
|
47
|
+
expect(result).to be_a(Regexp)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with AI-based generation' do
|
52
|
+
it 'fetches AI content when api_based_on is ai' do
|
53
|
+
result = generator.generate_text(
|
54
|
+
topic: 'technology',
|
55
|
+
length: 100,
|
56
|
+
api_based_on: 'ai',
|
57
|
+
api_key: api_key
|
58
|
+
)
|
59
|
+
expect(result).to be_a(String)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns error message when API key is missing' do
|
63
|
+
result = generator.generate_text(
|
64
|
+
topic: 'technology',
|
65
|
+
length: 100,
|
66
|
+
api_based_on: 'ai',
|
67
|
+
api_key: nil
|
68
|
+
)
|
69
|
+
expect(result).to include('OpenAI API key is required')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with Wikipedia-based generation' do
|
74
|
+
it 'fetches Wikipedia content when api_based_on is not ai' do
|
75
|
+
result = generator.generate_text(
|
76
|
+
topic: 'Ruby (programming language)',
|
77
|
+
length: 100,
|
78
|
+
api_based_on: 'wiki'
|
79
|
+
)
|
80
|
+
expect(result).to be_a(String)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'debug output' do
|
86
|
+
it 'outputs debug messages when debug is enabled' do
|
87
|
+
expect { generator_with_options.send(:debug_output, 'test message') }
|
88
|
+
.to output(/\[Debug\] test message/).to_stdout
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,48 +1,145 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: demo_lorem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Manmohan-menon
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '2.2'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '2.2'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
33
|
+
version: '13.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.18'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.18'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cgi
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.1.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.1'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.1.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: httparty
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.18'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.18.1
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0.18'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.18.1
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: json
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2.6'
|
116
|
+
type: :runtime
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '2.6'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: openai
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0.1'
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.1.0
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0.1'
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 0.1.0
|
46
143
|
description: Lorem Ipsum generator
|
47
144
|
email:
|
48
145
|
- manmohan.menon@gmail.com
|
@@ -50,37 +147,41 @@ executables: []
|
|
50
147
|
extensions: []
|
51
148
|
extra_rdoc_files: []
|
52
149
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- Gemfile
|
55
|
-
- LICENSE.txt
|
56
150
|
- README.md
|
57
|
-
- Rakefile
|
58
151
|
- demo_lorem.gemspec
|
59
152
|
- lib/demo_lorem.rb
|
153
|
+
- lib/demo_lorem/generator.rb
|
154
|
+
- lib/demo_lorem/helpers/ai_api_helper.rb
|
155
|
+
- lib/demo_lorem/helpers/nonai_api_helper.rb
|
156
|
+
- lib/demo_lorem/helpers/regex_helper.rb
|
60
157
|
- lib/demo_lorem/version.rb
|
61
|
-
|
158
|
+
- spec/demo_lorem/generator_spec.rb
|
159
|
+
homepage: https://github.com/Manmohan-menon/demo_lorem
|
62
160
|
licenses:
|
63
161
|
- MIT
|
162
|
+
metadata:
|
163
|
+
allowed_push_host: https://rubygems.org
|
164
|
+
homepage_uri: https://github.com/Manmohan-menon/demo_lorem
|
165
|
+
source_code_uri: https://github.com/Manmohan-menon/demo_lorem
|
166
|
+
changelog_uri: https://github.com/Manmohan-menon/demo_lorem
|
64
167
|
post_install_message:
|
65
168
|
rdoc_options: []
|
66
169
|
require_paths:
|
67
170
|
- lib
|
68
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
172
|
requirements:
|
71
|
-
- -
|
173
|
+
- - ">="
|
72
174
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
175
|
+
version: 2.6.0
|
74
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
177
|
requirements:
|
77
|
-
- -
|
178
|
+
- - ">="
|
78
179
|
- !ruby/object:Gem::Version
|
79
180
|
version: '0'
|
80
181
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 1.8.25
|
182
|
+
rubygems_version: 3.4.1
|
83
183
|
signing_key:
|
84
|
-
specification_version:
|
85
|
-
summary:
|
86
|
-
test_files:
|
184
|
+
specification_version: 4
|
185
|
+
summary: A dummy text generator like lorem ipsum or some user specific topic
|
186
|
+
test_files:
|
187
|
+
- spec/demo_lorem/generator_spec.rb
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Manmohan-menon
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|