questiongenerator 0.0.2 → 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41d61d976534cc4eecad47da3478fd1bff9a786f
4
+ data.tar.gz: bfc90e54cd448085dacf19e505798d0bff013a34
5
+ SHA512:
6
+ metadata.gz: de58d92b739865038ef2e51c7df558b7eea7d4999db4e524e89824c2ceef6e3227c22cba125d1af1119337395d1bf3e27dd619ffe85dd6fd469b48a9daf9dd04
7
+ data.tar.gz: 3f3628c3fca34c2be268e1a7befb6fa9349efcb620396503472cb87b28b49263cb8eafa5dc74dca1fdf6494127a8075bf07a18bd963f477210f2671ee232eb96
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # questiongenerator
2
2
 
3
- A simple question generator, used by justask.
3
+ A simple question generator, used by Retrospring (formerly justask).
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,7 @@ Add this line to your application's Gemfile:
10
10
 
11
11
  If you're feeling _edgy_, you can add this line instead:
12
12
 
13
- gem 'questiongenerator', git: 'https://github.com/justask/questiongenerator.git'
13
+ gem 'questiongenerator', git: 'https://github.com/retrospring/questiongenerator.git'
14
14
 
15
15
  ## Usage
16
16
 
@@ -21,18 +21,21 @@ require 'questiongenerator'
21
21
  QuestionGenerator.question_base_path = '/home/nilsding/questions'
22
22
  QuestionGenerator.default_locale = :en
23
23
 
24
+ # Compile the questions for increased randomness
25
+ QuestionGenerator.compile
26
+
24
27
  # Get some questions
25
28
  puts QuestionGenerator.generate
26
29
  # => "What is the best thing about the internet?"
27
30
 
28
31
  # You can also specify the locale, if you want to
29
- puts QuestionGenerator.generate :de
32
+ puts QuestionGenerator.generate locale: :de
30
33
  # => "Was war das letzte, das du gegessen hast?"
31
34
  ```
32
35
 
33
36
  ## Contributing
34
37
 
35
- 1. Fork it ( https://github.com/justask/questiongenerator/fork )
38
+ 1. Fork it ( https://github.com/retrospring/questiongenerator/fork )
36
39
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
40
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
41
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,20 +1,49 @@
1
1
  require 'yaml'
2
2
 
3
+ # Generates some questions.
3
4
  module QuestionGenerator
4
- VERSION = "0.0.2"
5
+ # Version of QuestionGenerator
6
+ VERSION = "0.1.0"
5
7
 
6
8
  class << self
9
+ # The base path to the questions (e.g. +'/home/nilsding/questions'+).
7
10
  attr_accessor :question_base_path
11
+ # The default locale, as a symbol.
8
12
  attr_accessor :default_locale
9
13
  end
10
14
 
11
- def self.setup
12
- yield self
15
+ # Generates a new question.
16
+ # @param options [Hash] A customizable set of options.
17
+ # @option options [Symbol] :locale (@default_locale) The target locale
18
+ # @option options [String] :prefix Prefix of the question, e.g. +'¿'+
19
+ # @option options [String] :suffix ('?') Suffix of the question, e.g. +' ?'+
20
+ # @option options [Boolean] :use_compiled (true) Use compiled questions
21
+ # instead of generating it. See also {compile}
22
+ # @return [String] String containing the generated question.
23
+ def self.generate(options = {})
24
+ opts = {
25
+ locale: @default_locale,
26
+ prefix: '',
27
+ suffix: '?',
28
+ use_compiled: true
29
+ }.merge!(options)
30
+ if opts[:use_compiled] and !@compiled[opts[:locale]].nil?
31
+ opts[:prefix] + @compiled[opts[:locale]].sample + opts[:suffix]
32
+ else
33
+ questions = YAML.load_file(File.expand_path("#{opts[:locale].to_s}.yml", @question_base_path))
34
+ opts[:prefix] + get_question(questions).strip + opts[:suffix]
35
+ end
13
36
  end
14
-
15
- def self.generate(locale = @default_locale)
16
- questions = YAML.load_file(File.expand_path("#{locale.to_s}.yml", @question_base_path))
17
- "#{get_question(questions).strip}?"
37
+
38
+ # Compiles all the questions and stores it into the +@compiled+ hash.
39
+ # @param options [Hash] A customizable set of options.
40
+ # @option options [Symbol] :locale (@default_locale) The target locale
41
+ def self.compile(options = {})
42
+ opts = {
43
+ locale: @default_locale
44
+ }.merge!(options)
45
+ questions = YAML.load_file(File.expand_path("#{opts[:locale].to_s}.yml", @question_base_path))
46
+ @compiled[@default_locale] = build(questions)
18
47
  end
19
48
 
20
49
  private
@@ -32,7 +61,24 @@ module QuestionGenerator
32
61
  end
33
62
  question
34
63
  end
64
+
65
+ def self.build(questions, q = "")
66
+ ary = []
67
+ if questions.is_a? Hash
68
+ questions.each do |k, v|
69
+ ary << build(v, "#{q}#{k} ")
70
+ end
71
+ elsif questions.is_a? Array
72
+ questions.each do |v|
73
+ ary << build(v, q)
74
+ end
75
+ elsif questions.is_a? String
76
+ return "#{q}#{questions}".strip
77
+ end
78
+ ary.flatten
79
+ end
35
80
 
36
81
  @question_base_path = File.expand_path("../questions/", __FILE__)
37
82
  @default_locale = :en
83
+ @compiled = {}
38
84
  end
@@ -1,10 +1,26 @@
1
1
  Do:
2
2
  you:
3
- like:
3
+ - recycle
4
+ - have:
5
+ - a:
6
+ - nickname
7
+ - any:
8
+ - siblings
9
+ - pets
10
+ - like:
4
11
  - social networks
5
12
  - muffins
6
13
  - video games
7
- want:
14
+ - the:
15
+ - city:
16
+ - or:
17
+ - country
18
+ - where you:
19
+ - live
20
+ - to:
21
+ - travel
22
+ - sing out loud when no one else is around
23
+ - want:
8
24
  - old times back
9
25
  - to know more:
10
26
  about:
@@ -17,8 +33,11 @@ Do:
17
33
  - money
18
34
  - friends
19
35
  - things than you need
20
- think that:
36
+ - think that:
21
37
  - late is better than never
38
+ - prefer:
39
+ to:
40
+ - take baths or showers
22
41
  your:
23
42
  friends:
24
43
  like:
@@ -35,6 +54,7 @@ Do:
35
54
  - life
36
55
  - hobbies
37
56
  - family
57
+ - friends
38
58
  - you
39
59
  much:
40
60
  about: *friends_know_much
@@ -68,10 +88,21 @@ What:
68
88
  - some drawings in your face
69
89
  - do:
70
90
  you:
91
+ do:
92
+ - for fun
93
+ - on:
94
+ - the:
95
+ - weekend
96
+ like:
97
+ more:
98
+ - dogs or cats
99
+ - shower or bath
100
+ - tea or coffee
71
101
  think:
72
102
  about:
73
103
  - the:
74
104
  - internet
105
+ - Bad Dragon
75
106
  - dragons
76
107
  - '"fact" accounts'
77
108
  - society
@@ -83,17 +114,48 @@ What:
83
114
  you:
84
115
  - enjoy the most
85
116
  - activities: *activity
117
+ - kind:
118
+ of:
119
+ animals:
120
+ - do you have
121
+ - habit:
122
+ do:
123
+ you:
124
+ really:
125
+ find:
126
+ cute:
127
+ - in a person?
86
128
  - is:
87
129
  your:
130
+ - first memory
131
+ - dream job
88
132
  - favourite:
89
- website:
90
- - ''
91
- - and why is it:
92
- - 9gag
93
- - Reddit
94
- - Twitter
95
- - Facebook
96
- - YouTube
133
+ - season
134
+ - video game
135
+ - board game
136
+ - sports team
137
+ - activity
138
+ - beverage
139
+ - internet browser
140
+ - piece of music
141
+ - console
142
+ - retrospring developer
143
+ - retrospring moderator
144
+ - snack
145
+ - food
146
+ - programming language:
147
+ - ''
148
+ - and why is it:
149
+ - PHP
150
+ website:
151
+ - ''
152
+ - and why is it:
153
+ - 4chan
154
+ - 9gag
155
+ - Reddit
156
+ - Twitter
157
+ - Facebook
158
+ - YouTube
97
159
  the:
98
160
  best: &is_the_best
99
161
  thing:
@@ -111,7 +173,12 @@ What:
111
173
  - if:
112
174
  - "they're bored"
113
175
  - ever
176
+ fast:
177
+ food:
178
+ - chain
114
179
  worst: *is_the_best
180
+ one:
181
+ - thing you would like to become better at
115
182
  - was:
116
183
  the:
117
184
  last:
@@ -128,13 +195,23 @@ What:
128
195
  Can:
129
196
  you:
130
197
  - swim
198
+ - speak:
199
+ - different:
200
+ - languages
131
201
  - play:
202
+ - any:
203
+ - sports
132
204
  - the:
133
205
  - piano
134
206
  - guitar
135
207
  - trumpet
136
208
  - baseball
137
209
  - ski
210
+ - cook
211
+ - dance
212
+ Are:
213
+ you:
214
+ - religious
138
215
  Have:
139
216
  you:
140
217
  ever:
@@ -158,13 +235,51 @@ Have:
158
235
  - caught:
159
236
  - "doing things you shouldn't do"
160
237
  - cheating
238
+ - mistaken for:
239
+ - someone else
161
240
  - listened to:
162
241
  - classical music
163
242
  - music:
164
243
  - "from the 80's"
165
244
  - dubstep
166
245
  - nightcore
246
+ - had:
247
+ - an:
248
+ - accident
167
249
  - written:
168
250
  - a love letter
169
251
  - code
170
252
  - in Japanese
253
+ How:
254
+ has:
255
+ your:
256
+ day:
257
+ - been
258
+ old:
259
+ are:
260
+ - you
261
+ Where:
262
+ do:
263
+ you:
264
+ - work
265
+ Which:
266
+ food:
267
+ do:
268
+ you:
269
+ - love
270
+ - hate
271
+ Who:
272
+ is:
273
+ the:
274
+ - most famous person you have met
275
+ Would:
276
+ you:
277
+ rather:
278
+ live:
279
+ - in:
280
+ - a city or in the countryside
281
+ - a flat or in a house
282
+ lose:
283
+ - an arm or a leg
284
+ be:
285
+ - the best player on a horrible team or the worst player on a great team
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["nilsding"]
10
10
  spec.email = ["nilsding@nilsding.org"]
11
11
  spec.summary = %q{A simple question generator.}
12
- spec.description = %q{A simple question generator.}
13
- spec.homepage = "https://github.com/justask/questiongenerator"
12
+ spec.description = %q{A simple question generator, used by Retrospring.}
13
+ spec.homepage = "https://github.com/retrospring/questiongenerator"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: questiongenerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - nilsding
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2015-01-18 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
@@ -22,7 +20,6 @@ dependencies:
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
@@ -30,7 +27,6 @@ dependencies:
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
@@ -38,12 +34,11 @@ dependencies:
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
40
  version: '0'
46
- description: A simple question generator.
41
+ description: A simple question generator, used by Retrospring.
47
42
  email:
48
43
  - nilsding@nilsding.org
49
44
  executables: []
@@ -58,30 +53,29 @@ files:
58
53
  - lib/questiongenerator.rb
59
54
  - lib/questions/en.yml
60
55
  - questiongenerator.gemspec
61
- homepage: https://github.com/justask/questiongenerator
56
+ homepage: https://github.com/retrospring/questiongenerator
62
57
  licenses:
63
58
  - MIT
59
+ metadata: {}
64
60
  post_install_message:
65
61
  rdoc_options: []
66
62
  require_paths:
67
63
  - lib
68
64
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
65
  requirements:
71
66
  - - '>='
72
67
  - !ruby/object:Gem::Version
73
68
  version: '0'
74
69
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
70
  requirements:
77
71
  - - '>='
78
72
  - !ruby/object:Gem::Version
79
73
  version: '0'
80
74
  requirements: []
81
75
  rubyforge_project:
82
- rubygems_version: 1.8.29
76
+ rubygems_version: 2.4.5
83
77
  signing_key:
84
- specification_version: 3
78
+ specification_version: 4
85
79
  summary: A simple question generator.
86
80
  test_files: []
87
81
  has_rdoc: