questiongenerator 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/questiongenerator.rb +45 -58
- data/lib/questions/en.yml +7 -12
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 758784d5d1a0314b051f925492230ceabd04b25b5c3ffd5449949008940e7f14
|
4
|
+
data.tar.gz: fea85ed6d03dc237f32fa53cee8c6644fcd7a02bf173216845f1120c571785de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c82dbab5148bfd888c3783ea1c5c4c37dadc6dcfec27ef5f6899fb8944cc23fbd432d41ebdaed8f4fdb25a5626f072d31a9730fa338ccb5ac8db05eac03137de
|
7
|
+
data.tar.gz: f03721ccb6170cd76dbd11663492972849b3e452f2c0ee0fec797c9fd29bb846f38a5c761a3eecfa1044973bdc2c2091b3146a87249db69a2cfe36b02355db7a
|
data/lib/questiongenerator.rb
CHANGED
@@ -1,86 +1,73 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "yaml"
|
4
4
|
|
5
5
|
# Generates some questions.
|
6
6
|
module QuestionGenerator
|
7
7
|
# Version of QuestionGenerator
|
8
|
-
VERSION = "1.
|
8
|
+
VERSION = "1.1.0"
|
9
9
|
|
10
10
|
class << self
|
11
11
|
# The base path to the questions (e.g. +'/home/nilsding/questions'+).
|
12
|
-
|
12
|
+
attr_reader :question_base_path
|
13
13
|
# The default locale, as a symbol.
|
14
14
|
attr_accessor :default_locale
|
15
15
|
end
|
16
16
|
|
17
|
+
module_function
|
18
|
+
|
17
19
|
# Generates a new question.
|
18
20
|
# @param options [Hash] A customizable set of options.
|
19
|
-
# @
|
20
|
-
# @
|
21
|
-
# @
|
22
|
-
# @option options [Boolean] :use_compiled (true) Use compiled questions
|
23
|
-
# instead of generating it. See also {compile}
|
21
|
+
# @param :locale [Symbol] The target locale
|
22
|
+
# @param :prefix [String] Prefix of the question, e.g. +'¿'+
|
23
|
+
# @param :suffix [String] Suffix of the question, e.g. +' ?'+
|
24
24
|
# @return [String] String containing the generated question.
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
suffix: '?',
|
30
|
-
use_compiled: true
|
31
|
-
}.merge!(options)
|
32
|
-
if opts[:use_compiled] and !@compiled[opts[:locale]].nil?
|
33
|
-
opts[:prefix] + @compiled[opts[:locale]].sample + opts[:suffix]
|
34
|
-
else
|
35
|
-
questions = YAML.load_file(File.expand_path("#{opts[:locale].to_s}.yml", @question_base_path))
|
36
|
-
opts[:prefix] + get_question(questions).strip + opts[:suffix]
|
37
|
-
end
|
25
|
+
def generate(locale: @default_locale, prefix: "", suffix: "?")
|
26
|
+
compile(locale:) unless @compiled.key?(locale)
|
27
|
+
|
28
|
+
prefix + @compiled[locale].sample + suffix
|
38
29
|
end
|
39
30
|
|
40
31
|
# Compiles all the questions and stores it into the +@compiled+ hash.
|
41
|
-
# @param
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
32
|
+
# @param :locale [Symbol] The target locale
|
33
|
+
def compile(locale: @default_locale)
|
34
|
+
questions = YAML.load_file(File.expand_path("#{locale}.yml", @question_base_path))
|
35
|
+
@compiled[locale] = build(questions)
|
36
|
+
end
|
37
|
+
|
38
|
+
def question_base_path=(path)
|
39
|
+
raise Errno::ENOENT.new(path) unless Dir.exist?(path)
|
40
|
+
|
41
|
+
@compiled = {} # new dir, force a recompile
|
42
|
+
@question_base_path = path
|
49
43
|
end
|
50
44
|
|
51
45
|
private
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
question
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.build(questions, q = "")
|
68
|
-
ary = []
|
69
|
-
if questions.is_a? Hash
|
70
|
-
questions.each do |k, v|
|
71
|
-
ary << build(v, "#{q}#{k} ")
|
72
|
-
end
|
73
|
-
elsif questions.is_a? Array
|
74
|
-
questions.each do |v|
|
75
|
-
ary << build(v, q)
|
47
|
+
module_function
|
48
|
+
|
49
|
+
def build(questions, q = "")
|
50
|
+
ary = []
|
51
|
+
|
52
|
+
case questions
|
53
|
+
when Hash
|
54
|
+
questions.each do |k, v|
|
55
|
+
Array(k).each do |variant|
|
56
|
+
ary << build(v, "#{q}#{variant} ")
|
76
57
|
end
|
77
|
-
elsif questions.is_a? String
|
78
|
-
return "#{q}#{questions}".strip
|
79
58
|
end
|
80
|
-
|
59
|
+
when Array
|
60
|
+
questions.each do |v|
|
61
|
+
ary << build(v, q)
|
62
|
+
end
|
63
|
+
when String
|
64
|
+
return "#{q}#{questions}".strip
|
81
65
|
end
|
82
66
|
|
83
|
-
|
84
|
-
|
85
|
-
|
67
|
+
ary.flatten
|
68
|
+
end
|
69
|
+
|
70
|
+
@question_base_path = File.expand_path("./questions/", __dir__)
|
71
|
+
@default_locale = :en
|
72
|
+
@compiled = {}
|
86
73
|
end
|
data/lib/questions/en.yml
CHANGED
@@ -47,17 +47,14 @@ Do:
|
|
47
47
|
- muffins
|
48
48
|
- video games
|
49
49
|
know:
|
50
|
-
too:
|
51
|
-
|
52
|
-
about: &friends_know_much
|
50
|
+
[much, too much]:
|
51
|
+
about:
|
53
52
|
- your:
|
54
53
|
- life
|
55
54
|
- hobbies
|
56
55
|
- family
|
57
56
|
- friends
|
58
57
|
- you
|
59
|
-
much:
|
60
|
-
about: *friends_know_much
|
61
58
|
What:
|
62
59
|
- was:
|
63
60
|
the:
|
@@ -118,11 +115,10 @@ What:
|
|
118
115
|
- foxes
|
119
116
|
- dogs
|
120
117
|
- lizards
|
121
|
-
- activity:
|
118
|
+
- [activity, activities]:
|
122
119
|
do:
|
123
120
|
you:
|
124
121
|
- enjoy the most
|
125
|
-
- activities: *activity
|
126
122
|
- kind:
|
127
123
|
of:
|
128
124
|
animals:
|
@@ -133,7 +129,7 @@ What:
|
|
133
129
|
really:
|
134
130
|
find:
|
135
131
|
cute:
|
136
|
-
- in a person
|
132
|
+
- in a person
|
137
133
|
- is:
|
138
134
|
your:
|
139
135
|
- first memory
|
@@ -169,7 +165,7 @@ What:
|
|
169
165
|
- Facebook
|
170
166
|
- YouTube
|
171
167
|
the:
|
172
|
-
best:
|
168
|
+
[best, worst]:
|
173
169
|
thing:
|
174
170
|
- about:
|
175
171
|
the:
|
@@ -188,7 +184,6 @@ What:
|
|
188
184
|
fast:
|
189
185
|
food:
|
190
186
|
- chain
|
191
|
-
worst: *is_the_best
|
192
187
|
one:
|
193
188
|
- thing you would like to become better at
|
194
189
|
- was:
|
@@ -199,10 +194,9 @@ What:
|
|
199
194
|
- did
|
200
195
|
- ate
|
201
196
|
- looked for
|
202
|
-
best:
|
197
|
+
[best, worst]:
|
203
198
|
thing:
|
204
199
|
- "you've eaten so far"
|
205
|
-
worst: *was_the_best
|
206
200
|
- languages do you know
|
207
201
|
- apps do you use daily
|
208
202
|
- 'is heavier: a kilogram of steel, or a kilogram of feathers'
|
@@ -219,6 +213,7 @@ Can:
|
|
219
213
|
- piano
|
220
214
|
- guitar
|
221
215
|
- trumpet
|
216
|
+
- saxophone
|
222
217
|
- baseball
|
223
218
|
- ski
|
224
219
|
- cook
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: questiongenerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nilsding
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,7 +83,7 @@ homepage: https://github.com/retrospring/questiongenerator
|
|
83
83
|
licenses:
|
84
84
|
- MIT
|
85
85
|
metadata: {}
|
86
|
-
post_install_message:
|
86
|
+
post_install_message:
|
87
87
|
rdoc_options: []
|
88
88
|
require_paths:
|
89
89
|
- lib
|
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
101
|
+
rubygems_version: 3.4.3
|
102
|
+
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: A simple question generator.
|
105
105
|
test_files:
|