initial commit
This commit is contained in:
commit
30553caf62
|
@ -0,0 +1,23 @@
|
|||
*.gem
|
||||
*.rbc
|
||||
.bundle
|
||||
.config
|
||||
.yardoc
|
||||
Gemfile.lock
|
||||
InstalledFiles
|
||||
_yardoc
|
||||
coverage
|
||||
doc/
|
||||
lib/bundler/man
|
||||
pkg
|
||||
rdoc
|
||||
spec/reports
|
||||
test/tmp
|
||||
test/version_tmp
|
||||
tmp
|
||||
*.bundle
|
||||
*.so
|
||||
*.o
|
||||
*.a
|
||||
mkmf.log
|
||||
.idea/
|
|
@ -0,0 +1,23 @@
|
|||
questiongenerator
|
||||
Copyright (c) 2014 nilsding
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,39 @@
|
|||
# questiongenerator
|
||||
|
||||
A simple question generator, used by justask.
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
gem 'questiongenerator'
|
||||
|
||||
If you're feeling _edgy_, you can add this line instead:
|
||||
|
||||
gem 'questiongenerator', git: 'https://github.com/justask/questiongenerator.git'
|
||||
|
||||
## Usage
|
||||
|
||||
``` ruby
|
||||
require 'questiongenerator'
|
||||
|
||||
# Configure it
|
||||
QuestionGenerator.question_base_path = '/home/nilsding/questions'
|
||||
QuestionGenerator.default_locale = :en
|
||||
|
||||
# Get some questions
|
||||
puts QuestionGenerator.generate
|
||||
# => "What is the best thing about the internet?"
|
||||
|
||||
# You can also specify the locale, if you want to
|
||||
puts QuestionGenerator.generate :de
|
||||
# => "Was war das letzte, das du gegessen hast?"
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it ( https://github.com/justask/questiongenerator/fork )
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create a new Pull Request
|
|
@ -0,0 +1,38 @@
|
|||
require 'yaml'
|
||||
|
||||
module QuestionGenerator
|
||||
VERSION = "0.0.1"
|
||||
|
||||
class << self
|
||||
attr_accessor :question_base_path
|
||||
attr_accessor :default_locale
|
||||
end
|
||||
|
||||
def self.setup
|
||||
yield self
|
||||
end
|
||||
|
||||
def self.generate(locale = @default_locale)
|
||||
questions = YAML.load_file(File.expand_path("#{locale.to_s}.yml", @question_base_path))
|
||||
"#{get_question(questions)}?"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.get_question questions
|
||||
question = ""
|
||||
if questions.is_a? Hash
|
||||
key = questions.keys.sample
|
||||
value = questions[key]
|
||||
question = "#{key} #{get_question(value)}"
|
||||
elsif questions.is_a? Array
|
||||
question = get_question questions.sample
|
||||
elsif questions.is_a? String
|
||||
question = questions
|
||||
end
|
||||
question
|
||||
end
|
||||
|
||||
@question_base_path = File.expand_path("../questions/", __FILE__)
|
||||
@default_locale = :en
|
||||
end
|
|
@ -0,0 +1,68 @@
|
|||
Do:
|
||||
you:
|
||||
like:
|
||||
- social networks
|
||||
- muffins
|
||||
- video games
|
||||
your:
|
||||
friends:
|
||||
like:
|
||||
- you:
|
||||
- the way you are
|
||||
- social networks
|
||||
- muffins
|
||||
- video games
|
||||
know:
|
||||
much:
|
||||
about:
|
||||
- your:
|
||||
- life
|
||||
- hobbies
|
||||
- family
|
||||
- you
|
||||
What:
|
||||
was:
|
||||
the:
|
||||
last:
|
||||
thing:
|
||||
you:
|
||||
have:
|
||||
- eaten
|
||||
- done
|
||||
your:
|
||||
favourite:
|
||||
song:
|
||||
- as a 5 year old
|
||||
- from a few weeks ago
|
||||
would:
|
||||
you:
|
||||
do:
|
||||
if:
|
||||
you:
|
||||
had:
|
||||
- one million dollars
|
||||
- the ability to fly
|
||||
were:
|
||||
- a dragon
|
||||
do:
|
||||
you:
|
||||
think:
|
||||
about:
|
||||
- the:
|
||||
- internet
|
||||
- dragons
|
||||
is:
|
||||
the:
|
||||
best: &is_the_best
|
||||
thing:
|
||||
about:
|
||||
the:
|
||||
- internet
|
||||
your:
|
||||
- favourite:
|
||||
- series
|
||||
- movie
|
||||
- book
|
||||
- country
|
||||
- hometown
|
||||
worst: *is_the_best
|
|
@ -0,0 +1,23 @@
|
|||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'questiongenerator'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "questiongenerator"
|
||||
spec.version = QuestionGenerator::VERSION
|
||||
spec.authors = ["nilsding"]
|
||||
spec.email = ["nilsding@nilsding.org"]
|
||||
spec.summary = %q{A simple question generator.}
|
||||
spec.description = %q{A simple question generator.}
|
||||
spec.homepage = "https://github.com/justask/questiongenerator"
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0")
|
||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.6"
|
||||
spec.add_development_dependency "rake"
|
||||
end
|
Loading…
Reference in New Issue