anyq 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/anyq.rb +66 -0
- data/lib/quotes.json +37 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7414211fa41ce2b9c1ab04016737eac1d465743989411cf5bc0d16202c11f05e
|
4
|
+
data.tar.gz: 9ee86905f18349f62b830aa95b63ea84f1da88b3e09534a9107834990b207c38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6a9778204dcee822db7d9bfabbd8014de043ba3670559724e7ae8a117f45f585a1bef240c3c81f2b209a263cca38b688747e7efe4941efde7cb76b3116843c9
|
7
|
+
data.tar.gz: b6f6ca1c063e2130c6f0b910dd3ccc57084a4fe39531fc7e710accf9606bb13dbdffc441a2f8948e7950dda6faebd29230f9ae8ddbc1964dec48b4988ab7e6dc
|
data/lib/anyq.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = 'Usage: anyq [options]'
|
8
|
+
opts.program_name = 'anyq'
|
9
|
+
opts.version = '0.0.1'
|
10
|
+
|
11
|
+
opts.on('-q', '--quote', 'Print only the quote') do |q|
|
12
|
+
options[:quote] = q
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('-a', '--author', 'Print the author of the quote') do |a|
|
16
|
+
options[:author] = a
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-s', '--source', 'Print the source of the quote') do |s|
|
20
|
+
options[:source] = s
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-Q', '--new-quote QUOTE', 'Add a quote to the JSON file') do |q|
|
24
|
+
options[:new_quote] = q
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-A', '--new-author AUTHOR', 'Specify the author of the quote') do |a|
|
28
|
+
options[:new_author] = a
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-S', '--new-source SOURCE', 'Specify the source of the quote') do |s|
|
32
|
+
options[:new_source] = s
|
33
|
+
end
|
34
|
+
end.parse!
|
35
|
+
|
36
|
+
quotes_file = File.read('./lib/quotes.json')
|
37
|
+
quotes = JSON.parse(quotes_file)
|
38
|
+
|
39
|
+
if options[:new_quote]
|
40
|
+
new_quote = {
|
41
|
+
'quote': options[:new_quote],
|
42
|
+
'author': options[:new_author] || 'Unknown',
|
43
|
+
'source': options[:new_source] || 'Unknown'
|
44
|
+
}
|
45
|
+
quotes << new_quote
|
46
|
+
|
47
|
+
File.write('./quotes.json', JSON.generate(quotes))
|
48
|
+
|
49
|
+
puts 'New quote added'
|
50
|
+
else
|
51
|
+
random_quote = quotes[SecureRandom.random_number(quotes.length)]
|
52
|
+
|
53
|
+
if options[:quote]
|
54
|
+
puts random_quote['quote']
|
55
|
+
|
56
|
+
if options[:author] && options[:source]
|
57
|
+
puts "-- #{random_quote['author']} (#{random_quote['source']})"
|
58
|
+
else
|
59
|
+
puts "-- #{random_quote['author']}" if options[:author]
|
60
|
+
puts "Source: #{random_quote['source']}" if options[:source]
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts random_quote['quote']
|
64
|
+
puts "-- #{random_quote['author']} (#{random_quote['source']})"
|
65
|
+
end
|
66
|
+
end
|
data/lib/quotes.json
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"quote": "The only way to truly succeed in life is to constantly strive for mediocrity.",
|
4
|
+
"author": "Jane Doe",
|
5
|
+
"source": "Mediocrity: The Key to Success"
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"quote": "The only limit to our potential is the size of our imagination.",
|
9
|
+
"author": "John Smith",
|
10
|
+
"source": "Unleashing Your Inner Genius"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"quote": "The only thing standing between you and greatness is your fear of failure.",
|
14
|
+
"author": "Sarah Johnson",
|
15
|
+
"source": "Overcoming Your Fears"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"quote": "The greatest achievements in life are not accomplished alone, but through collaboration and teamwork.",
|
19
|
+
"author": "David Williams",
|
20
|
+
"source": "The Power of Community"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"quote": "The key to happiness is not in material possessions, but in the simple things in life.",
|
24
|
+
"author": "Emily Brown",
|
25
|
+
"source": "Finding Joy in the Mundane"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"quote": true,
|
29
|
+
"author": "Lorem Smith",
|
30
|
+
"source": "That Guy"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"quote": "Another one",
|
34
|
+
"author": "Unknown",
|
35
|
+
"source": "Unknown"
|
36
|
+
}
|
37
|
+
]
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anyq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Angel Ortega
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem that prints a random quote form a collection
|
14
|
+
email: hey@luisangel.me
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/anyq.rb
|
20
|
+
- lib/quotes.json
|
21
|
+
homepage: https://github.com/LinkSake/anyq
|
22
|
+
licenses:
|
23
|
+
- GPL-3.0-or-later
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.3.26
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Give me any quote
|
44
|
+
test_files: []
|