trivia_factory 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35dd5c988711f9b1070a871dede6403bada35633
4
- data.tar.gz: d40d894a398b023662cf77d64e0296f7abb8d055
3
+ metadata.gz: 8d89fc9c5a18eca8768bebcdfd70affbe48c4a59
4
+ data.tar.gz: 767b16bc29ee1dd2aa3d5aa3807cb7268336bb18
5
5
  SHA512:
6
- metadata.gz: 63c9524357b8d83d61e9263c3a143a085beb69c1b0ccc696e6a5575ce22c24a67f6381709737f6fb8adbcf4a274c6261d5208d79ac0623c01c42452b6646814f
7
- data.tar.gz: 0b60c5d3cb15fcc86922aadb18d221d384f9d278ff74c2f465e0afd8cfe23a23a767595d4e851eb45aa0e04bf83d0cfedb0a96778db543dbe2de2d0706fa914d
6
+ metadata.gz: ac8b110987209af9f9e7c1d6330ee2f4cb89cd56db048ca0a6876dd582603fc26d47cf9c8d220b7c32207719768f367d9dec2b9615b8f2e76cb3221ff51d5ec0
7
+ data.tar.gz: 5bc1a101006e92f17526320ae5fc63460eb2bc33d227267f0cf5b0cfc959bd371467c67a41a64dc3fb38242aff32744e04043ab85ca883d3cf3feea9dcf1e7fc
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Trivia Factory
2
2
 
3
3
  Ruby gem for creating tons of sample trivia/test questions. Intended for use in specs or apps that need questions.
4
- Think of it as [Faker](https://github.com/stympy/faker) for trivia questions.
4
+ Think of it as [Faker](https://github.com/stympy/faker) for trivia questions + answers. It should be able to create
5
+ thousands of unique questions.
5
6
 
6
7
  Originally part of a sports trivia app I had that was somewhat popular (Hat Trick), this gem uses tables of data (in CSV form) to
7
8
  create random questions.
@@ -61,25 +62,24 @@ Question objects have the following attributes (which are also available as keys
61
62
 
62
63
  Currently the following question categories exist as subclasses of `TriviaFactory::Question`:
63
64
 
64
- **TriviaFactory::MathQuestion**: generates a basic integer addition problem (fill in the blank).
65
+ `TriviaFactory::MathQuestion`: generates a basic integer addition, subtraction, multiplication, or division problem (fill in the blank).
65
66
 
66
- **TriviaFactory::SportsQuestion**: generates a sports trivia question (multiple choice).
67
+ `TriviaFactory::SportsQuestion`: generates a sports trivia question (multiple choice).
67
68
 
68
- **TriviaFactory::UsStateCapitalsQuestion**: generates a question about US state capitals.
69
+ `TriviaFactory::UsStateCapitalsQuestion`: generates a question about US state capitals (multiple choice).
69
70
 
70
- **TriviaFactory::CapitalCitiesQuestion**: generates a question about capital cities (worldwide)
71
+ `TriviaFactory::CapitalCitiesQuestion`: generates a question about worldwide capital cities (fill in the blank)
71
72
 
72
- **TriviaFactory::AcademyAwardsQuestion**: generates a question about academy award winners
73
+ `TriviaFactory::AcademyAwardsQuestion`: generates a question about academy award winners (multiple choice)
73
74
 
74
- **TriviaFactory::VocabularyQuestion**: generates a multiple choice vocabulary *word* <-> *definition* question. From a list of 1,000 vocabulary study words.
75
+ `TriviaFactory::VocabularyQuestion`: generates a vocabulary *word* <-> *definition* question. From a list of 1,000 vocabulary study words. (multiple choice)
75
76
 
76
- To create a question from any of these types, simply call the `generate()` method on any of the classes.
77
+ To create a question from any of these types, simply call the `.generate()` method on any of the classes.
77
78
 
78
79
  ### More examples
79
80
 
80
81
  ```
81
- # Math question can accept a max param that can limit the size of operands (default is 100)
82
- q = TriviaFactory::MathQuestion.generate(20)
82
+ q = TriviaFactory::MathQuestion.generate
83
83
  q.to_h
84
84
  => {
85
85
  :label => "5 + 5 = _____?",
@@ -3,7 +3,7 @@ module TriviaFactory
3
3
 
4
4
  class << self
5
5
  def generate
6
- # File: vocabulary.csv
6
+ # File: academy_awards.csv
7
7
  # 0: award
8
8
  # 1: winner
9
9
  # 2: movie
@@ -11,7 +11,6 @@ module TriviaFactory
11
11
  question = TriviaFactory::Question.new
12
12
  data = fetch_csv('academy_awards')
13
13
  answer_row = data.sample
14
- question = TriviaFactory::VocabularyQuestion.new
15
14
  question.label = "In #{answer_row[3]} #{answer_row[1]} won the academy award for #{answer_row[0]} for what film?"
16
15
  question.choices = [answer_row[2]]
17
16
  question.question_type = :multiple_choice
@@ -3,17 +3,50 @@ module TriviaFactory
3
3
 
4
4
  QUESTION_SUB_TYPES = [:addition, :subtraction, :multiplication, :division].freeze
5
5
 
6
+ def initialize(subtype = :addition)
7
+ @question_type = :fill_in_the_blank
8
+ @answer_type = :integer
9
+ @choices = []
10
+ raise 'Invalid sub type for TriviaFactory::MathQuestion' unless QUESTION_SUB_TYPES.include?(subtype)
11
+ self.send("build_#{subtype.to_s}")
12
+ end
13
+
14
+ def build_addition
15
+ rng = Random.new
16
+ first = rng.rand(100)
17
+ second = rng.rand(100)
18
+ @label = "#{first} + #{second} = _____?"
19
+ @answer = first + second
20
+ end
21
+
22
+ def build_subtraction
23
+ rng = Random.new
24
+ first = rng.rand(100)
25
+ second = rng.rand(100)
26
+ @label = "#{first + second} - #{first} = _____?"
27
+ @answer = second
28
+ end
29
+
30
+ def build_multiplication
31
+ rng = Random.new
32
+ first = rng.rand(12)
33
+ second = rng.rand(12)
34
+ @label = "#{first} X #{second} = _____?"
35
+ @answer = first * second
36
+ end
37
+
38
+ def build_division
39
+ rng = Random.new
40
+ first = 1 + rng.rand(11)
41
+ second = 1 + rng.rand(11)
42
+ @label = "#{first * second} ÷ #{first} = _____?"
43
+ @answer = second
44
+ end
45
+
6
46
  class << self
7
- def generate(max = 100)
8
- question = TriviaFactory::Question.new
9
- rng = Random.new
10
- first = rng.rand(max)
11
- second = rng.rand(max)
12
- question.label = "#{first} + #{second} = _____?"
13
- question.question_type = :fill_in_the_blank
14
- question.answer_type = :integer
15
- question.answer = first + second
16
- question.choices = []
47
+ def generate
48
+ sub_type = QUESTION_SUB_TYPES.sample
49
+ question = TriviaFactory::MathQuestion.new(sub_type)
17
50
  question
18
51
  end
19
52
  end
@@ -5,7 +5,7 @@ module TriviaFactory
5
5
 
6
6
  class << self
7
7
  def generate
8
- # File: vocabulary.csv
8
+ # File: sports_champions.csv
9
9
  # 0: year
10
10
  # 1: championship ("wold series")
11
11
  # 2: counter/number ("IV" for super bowl)
@@ -15,7 +15,6 @@ module TriviaFactory
15
15
  question = TriviaFactory::Question.new
16
16
  data = fetch_csv('sports_champions')
17
17
  answer_row = data.sample
18
- question = TriviaFactory::VocabularyQuestion.new
19
18
  if answer_row[2].nil?
20
19
  question.label = "In #{answer_row[0]} who defeated the #{answer_row[4]} to win the #{answer_row[1]}?"
21
20
  else
@@ -1,3 +1,3 @@
1
1
  module TriviaFactory
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -46,8 +46,8 @@ module TriviaFactory
46
46
  TriviaFactory::Question.new
47
47
  end
48
48
 
49
- def math(max = 100)
50
- TriviaFactory::MathQuestion.generate(max)
49
+ def math
50
+ TriviaFactory::MathQuestion.generate
51
51
  end
52
52
 
53
53
  def us_state_capitals
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trivia_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Callmeed
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-15 00:00:00.000000000 Z
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler