random_facts 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,198 @@
1
+ [
2
+ {
3
+ "type": "tv",
4
+ "fact": "1 in every 4 Americans has appeared on television."
5
+ },
6
+ {
7
+ "type": "tv",
8
+ "fact": "A NUKE InterNETWORK poll found that 52 percent of Internet users have cut back on watching TV in order to spend more time online; 12 percent have cut back on seeing friends."
9
+ },
10
+ {
11
+ "type": "tv",
12
+ "fact": "Alan Thicke, the father in the TV show Growing Pains wrote the theme songs for The Facts of Life and Diff'rent Strokes."
13
+ },
14
+ {
15
+ "type": "tv",
16
+ "fact": "Before Late Night Television, Jay Leno appeared in an episode of Laverne and Shirley."
17
+ },
18
+ {
19
+ "type": "tv",
20
+ "fact": "Besides Star Trek, William Shatner, Leonard Nemoy, James Doohan, and Geoge Takei have all appeared at one time or another on \"The Twilight Zone.\""
21
+ },
22
+ {
23
+ "type": "tv",
24
+ "fact": "Boris Karloff is the narrator of the seasonal television special \"How the Grinch Stole Christmas.\""
25
+ },
26
+ {
27
+ "type": "tv",
28
+ "fact": "Duke Nukem for Macintosh includes as an Easter Egg the original 1984 Apple TV spot."
29
+ },
30
+ {
31
+ "type": "tv",
32
+ "fact": "Franklin D. Roosevelt was the first president to be televised, in ceremonies opening the New York World's Fair in April 1939."
33
+ },
34
+ {
35
+ "type": "tv",
36
+ "fact": "Franklin D. Roosevelt was the first president to be televised, on April 1939 at opening of the New York World's Fair."
37
+ },
38
+ {
39
+ "type": "tv",
40
+ "fact": "In every episode of Seinfeld there is a Superman somewhere."
41
+ },
42
+ {
43
+ "type": "tv",
44
+ "fact": "In the 1940s, the FCC assigned television's Channel 1 to mobile services (two-way radios in taxicabs, for instance) but did not re-number the other channel assignments. That is why your TV set has channels 2 and up but no channel 1."
45
+ },
46
+ {
47
+ "type": "tv",
48
+ "fact": "In the Durango desert, in Mexico, there's a creepy spot called the 'Zone of Silence'. You can't pick up clear TV or radio signals. And locals say fireballs sometimes appear in the sky."
49
+ },
50
+ {
51
+ "type": "tv",
52
+ "fact": "In the TV series I Love Lucy, Ricki Ricardo never actually said “Lucy you have some ‘splaining to do”"
53
+ },
54
+ {
55
+ "type": "tv",
56
+ "fact": "In the early 1940s, the FCC assigned television’s Channel 1 to mobile services (like two-way radios in taxis) but did not re-number the other channel assignments."
57
+ },
58
+ {
59
+ "type": "tv",
60
+ "fact": "In the original Star Trek series Captain Kirk’s middle name was Tiberius."
61
+ },
62
+ {
63
+ "type": "tv",
64
+ "fact": "In the theme song from \"The Flintstones\", the lineafter \"Let's ride with the family down the street\" is 'Through the courtesy of Fred's two feet.'"
65
+ },
66
+ {
67
+ "type": "tv",
68
+ "fact": "It takes the interaction of 72 different muscles to produce human speech."
69
+ },
70
+ {
71
+ "type": "tv",
72
+ "fact": "James Doohan, who played Lt. Commander Montgomery Scott on Star Trek, was missing the entire middle finger of his right hand."
73
+ },
74
+ {
75
+ "type": "tv",
76
+ "fact": "MTV first aired at 12:01 AM on August 1, 1981. The first video was \"Video Killed the Radio Star\" by the Buggles."
77
+ },
78
+ {
79
+ "type": "tv",
80
+ "fact": "One in every 4 Americans has appeared on television at least once in their life."
81
+ },
82
+ {
83
+ "type": "tv",
84
+ "fact": "Recycling one glass jar saves enough energy to watch TV for 3 hours."
85
+ },
86
+ {
87
+ "type": "tv",
88
+ "fact": "Television horse Mr. Ed was foaled in 1949 in El Monte, California. Mr. Ed's original name was Bamboo Harvester. Raised as a parade and show horse he was once owned by the president of the California Palomino Society. He died in Tahlequah, Oklahoma, on February 28, 1979, at 30 years old. Tahlequah was also the \"home office\" for \"Late Night with David Letterman's Top Ten List\" for several years."
89
+ },
90
+ {
91
+ "type": "tv",
92
+ "fact": "The Andy Griffth Show was the first spin-off in TV history. It was a spin-off of the Danny Thomas Show."
93
+ },
94
+ {
95
+ "type": "tv",
96
+ "fact": "The First episode of “Joanie Loves Chachi” (Happy Days spinoff) was the highest rated American TV program on Korean television. “Chachi” is Korean for penis."
97
+ },
98
+ {
99
+ "type": "tv",
100
+ "fact": "The Les Nessman character on the TV series WKRP in Cincinnati wore a band-aid in every episode. Either on himself, his glasses, or his clothing."
101
+ },
102
+ {
103
+ "type": "tv",
104
+ "fact": "The Simpsons is the longest running animated series on TV."
105
+ },
106
+ {
107
+ "type": "tv",
108
+ "fact": "The TV sitcom Seinfeld was originally named \"The Seinfeld Chronicles\". The pilot which was broadcast in 1989 also featured a kooky neighbor named Kessler. This character later became known as Kramer."
109
+ },
110
+ {
111
+ "type": "tv",
112
+ "fact": "The average American family views television six hours each day."
113
+ },
114
+ {
115
+ "type": "tv",
116
+ "fact": "The average American spends about a year and a half of his or her life watching commercials on television."
117
+ },
118
+ {
119
+ "type": "tv",
120
+ "fact": "The average Japanese household watches more than 10 hours of television a day."
121
+ },
122
+ {
123
+ "type": "tv",
124
+ "fact": "The average child spends approximately 28 hours a week watching television, which is around the same amount of time they spend in school."
125
+ },
126
+ {
127
+ "type": "tv",
128
+ "fact": "The first TV couple to share a bed was not on \"The Brady Bunch\" or \"The Munsters,\" but was on \"The Mary Kay and Johnny\" show in 1947. It was the first situation comedy ever."
129
+ },
130
+ {
131
+ "type": "tv",
132
+ "fact": "The first couple to be shown in bed together on prime time television were Fred and Wilma Flintstone."
133
+ },
134
+ {
135
+ "type": "tv",
136
+ "fact": "The first ever TV commercial in the U.S. was for Bulova watches. It aired in 1941 on WNBT, New York, and cost Bulova 9 dollars."
137
+ },
138
+ {
139
+ "type": "tv",
140
+ "fact": "The first ever televised murder case appeared on TV in 1955, Dec. 5-9. The accused was Harry Washburn."
141
+ },
142
+ {
143
+ "type": "tv",
144
+ "fact": "The first image ever transmitted on TV was Felix the Cat."
145
+ },
146
+ {
147
+ "type": "tv",
148
+ "fact": "The first televised tour of the White House aired on February 14 in 1962. First Lady Jackie Kennedy hosted the tour."
149
+ },
150
+ {
151
+ "type": "tv",
152
+ "fact": "The first television shows to have the characters take bathroom breaks were \"All in the family\" and \"Married with children.\""
153
+ },
154
+ {
155
+ "type": "tv",
156
+ "fact": "The first toilet ever seen on television was on \"Leave It To Beaver.\""
157
+ },
158
+ {
159
+ "type": "tv",
160
+ "fact": "The first toilet ever seen on television was on \"Leave It to Beaver.\""
161
+ },
162
+ {
163
+ "type": "tv",
164
+ "fact": "The original captain of Star Trek's starship \"Enterprise\" was Jeffrey Hunter - not William Shatner - as Christopher Pike, in the pilot episode \"The cage\" (1964). The cast was quite different from that of the classic series except for Leonard Nimoy as Spock."
165
+ },
166
+ {
167
+ "type": "tv",
168
+ "fact": "The original host of “Jeopardy” was Art Fleming."
169
+ },
170
+ {
171
+ "type": "tv",
172
+ "fact": "The proceedings in the British Parliament are meant to be in private, even though they are now televised. So, if the MPs want to have a secret session, one of them points to the gallery from which the public watch, and calls \"I spy strangers!\", whereupon the House votes \"that the strangers do withdraw.\""
173
+ },
174
+ {
175
+ "type": "tv",
176
+ "fact": "The real name of television’s Mister Ed was Bamboo Harvester."
177
+ },
178
+ {
179
+ "type": "tv",
180
+ "fact": "The reason wheels seem to spin backwards on a camera is because when you film something, you are really taking a series of still images and then replaying them so fast that the eye is fooled into thinking it is a continuous stream of images. The eye can see about 12-14 frames per second. Because of a physical law called the Nyquist Sampling Theorem you need to display frames twice as fast as the eye can see to fool it into seeing it as a continuous movie (Nyquist showed mathematically why that is true). So, imagine you have a wheel that is spinning exactly once every second. If you took a picture at the same rate, it would look like it is standing still. That's because it rotates exactly once every time you take a picture. Now take a picture just a little bit faster than 1 per second. Now every time you take a picture, the wheel has not quite made it all the way around; maybe it will have gone 350 degrees around, so it's 10 degrees behind the first frame. The next frame it will have gone another 350 degrees, making it now 20 degrees behind the first frame, and so on. When you play the film back, it will look like the wheel is moving backwards, even though you know it was going forwards. The opposite effect happens when you take pictures a bit slower than the rotation rate. It gets more complicated when the wheel does not rotate at a constant rate, like when a car accelerates. The next time you watch TV or go to the movies, watch the wheels as a car speeds up. You might see the wheel appear to go backwards, them stop, then go forwards, all while the car is moving forwards."
181
+ },
182
+ {
183
+ "type": "tv",
184
+ "fact": "They NEVER said \"Beam me up, Scotty\" on Star Trek."
185
+ },
186
+ {
187
+ "type": "tv",
188
+ "fact": "Treasure Island was created by Robert Louis Stevenson on a lark. Drawing a treasure map for his stepson on a rainy day, Stevenson was urged by the child to make up stories to go along with the drawings. Stevenson liked the stories so much he wrote them down, and these became the basis for his great novel."
189
+ },
190
+ {
191
+ "type": "tv",
192
+ "fact": "When Patty Hearst was kidnapped, she was watching the TV Show \"The Magician\" starring Bill Bixby."
193
+ },
194
+ {
195
+ "type": "tv",
196
+ "fact": "You burn more calories sleeping than you do watching TV."
197
+ }
198
+ ]
data/data/sources.json ADDED
@@ -0,0 +1,27 @@
1
+ [
2
+ "http://www.world-english.org/facts.htm",
3
+ "http://www.buzzfeed.com/adamdavis/useless-facts#.cn1xDEkdB",
4
+ "http://freshnerd.com/2009/09/100-useless-facts-for-no-reason/",
5
+ "http://blablablablabla.com/facts/",
6
+ "http://www.angelfire.com/ca6/uselessfacts/",
7
+ "http://www.mundayweb.com/uselessfacts/american.php",
8
+ "http://laughbreak.com/lists/useless-facts/",
9
+ "http://www.useless-facts.net/",
10
+ "http://www.begent.org/funfact.htm",
11
+ "http://uselessfacts.net/",
12
+ "http://www.livin3.com/blogs/positive-life-blog/9939728-50-cool-and-weird-fun-facts-that-you-should-know",
13
+ "http://bootstrike.com/",
14
+ "http://www.methodshop.com/picts/500-facts/",
15
+ "http://www.wowhead.com/forums&topic=118484/useless-facts",
16
+ "http://www.allowe.com/laughs/book/Useless%20Facts.htm",
17
+ "http://www.cs.cmu.edu/~bingbin/",
18
+ "http://www.thefactsite.com/2011/07/top-100-random-funny-facts.html",
19
+ "https://triviaoftheday.wordpress.com/",
20
+ "http://www.brainist.com/trivia-questions/",
21
+ "http://www.funology.com/trivia-and-strange-facts/",
22
+ "http://www.pubquizreference.co.uk/",
23
+ "http://dan.hersam.com/lists/trivia.html",
24
+ "http://www.inthe80s.com/80striva.shtml",
25
+ "http://www.historyorb.com/",
26
+ "http://catfacts-api.appspot.com/"
27
+ ]
data/lib/random_facts.rb CHANGED
@@ -5,20 +5,21 @@ module RandomFacts
5
5
  ROOT = File.expand_path("../..", __FILE__)
6
6
 
7
7
  def self.process(options = {})
8
- file = File.read("#{ROOT}/data/facts.json")
9
- data_hash = JSON.parse(file)
8
+ data_hash = read_all_hash_files
10
9
  random_numbers = []
11
10
  final_data = []
12
11
 
13
12
  # if options type is given filter out only the facts that refer to that kind of type
14
- if options[:type].present?
15
- filtered_data = data_hash['facts'].select { |fact| fact['type'] == options[:type] }
13
+ if options[:type].nil?
14
+ filtered_data = data_hash
16
15
  else
17
- filtered_data = data_hash['facts']
16
+ filtered_data = data_hash.select { |fact| fact['type'] == options[:type] }
18
17
  end
19
18
 
20
19
  # if option size is given try to produce random numbers to select
21
- if options[:size].present? && filtered_data.size > 0
20
+ if options[:size].nil? || filtered_data.size == 0
21
+ final_data = filtered_data
22
+ else
22
23
  while random_numbers.size < options[:size]
23
24
  number = rand(filtered_data.size - 1)
24
25
  unless random_numbers.include? number
@@ -29,17 +30,39 @@ module RandomFacts
29
30
  random_numbers.each do |index|
30
31
  final_data << filtered_data[index]
31
32
  end
32
- else
33
- final_data = filtered_data
34
33
  end
35
34
 
36
35
  final_data.map { |fact| fact['fact'] }
37
36
  end
38
37
 
39
38
  def self.valid_types
40
- file = File.read("#{ROOT}/data/facts.json")
41
- data_hash = JSON.parse(file)
42
- data_hash['facts'].collect { |fact| fact['type'] }.uniq.sort
39
+ data_hash = read_all_hash_files
40
+ data_hash.collect { |fact| fact['type'] }.uniq.sort
41
+ end
42
+
43
+ def self.sources
44
+ file_to_read = "#{ROOT}/data/sources.json"
45
+ data = []
46
+ file = File.read(file_to_read)
47
+ data << JSON.parse(file).flatten
48
+
49
+ data.flatten
50
+ end
51
+
52
+ #########
53
+ protected
54
+ #########
55
+
56
+ def self.read_all_hash_files
57
+ files_to_read = Dir["#{ROOT}/data/facts/*.json"]
58
+ data = []
59
+
60
+ files_to_read.each do |file_to_read|
61
+ file = File.read(file_to_read)
62
+ data << JSON.parse(file).flatten
63
+ end
64
+
65
+ data.flatten
43
66
  end
44
67
  end
45
68
  end
@@ -1,3 +1,3 @@
1
1
  module RandomFacts
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/random_facts.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["billkall@gmail.com"]
11
11
  spec.summary = %q{A random facts generator}
12
12
  spec.description = %q{A gem to provide random facts based on requested parameters}
13
- spec.homepage = "https://github.com/arcanoid/random_facts"
13
+ spec.homepage = "https://rubygems.org/gems/random_facts"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.7'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec'
24
+
25
+ spec.required_ruby_version = '~> 2.2.3'
24
26
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe RandomFacts::Generator do
4
+ describe '#process' do
5
+ it 'should respond with full list when no option is given' do
6
+ output = RandomFacts::Generator.process
7
+ expect(output).to be_kind_of Array
8
+ expect(output.size).to eq(3162)
9
+ end
10
+
11
+ it 'should respond with proper list when size option is given' do
12
+ output = RandomFacts::Generator.process({:size => 10})
13
+ expect(output).to be_kind_of Array
14
+ expect(output.size).to eq(10)
15
+ end
16
+
17
+ it 'should respond with proper list when type option is given' do
18
+ output = RandomFacts::Generator.process({:type => 'animal kingdom'})
19
+ expect(output).to be_kind_of Array
20
+ expect(output.size).to eq(1399)
21
+ end
22
+ end
23
+
24
+ describe '#sources' do
25
+ it 'should respond with proper list' do
26
+ output = RandomFacts::Generator.sources
27
+ expect(output).to be_kind_of Array
28
+ expect(output.size).to eq(25)
29
+ end
30
+ end
31
+
32
+ describe '#valid_types' do
33
+ it 'should respond with proper list' do
34
+ output = RandomFacts::Generator.valid_types
35
+ expect(output).to be_kind_of Array
36
+ expect(output.size).to eq(25)
37
+ expect(output).to eq([
38
+ 'animal kingdom',
39
+ 'cartoon',
40
+ 'customs',
41
+ 'earth',
42
+ 'expressions',
43
+ 'flags',
44
+ 'food',
45
+ 'grammar',
46
+ 'history',
47
+ 'human anatomy',
48
+ 'inventions',
49
+ 'legal',
50
+ 'literature',
51
+ 'math',
52
+ 'monetary',
53
+ 'movies',
54
+ 'music',
55
+ 'plants',
56
+ 'records',
57
+ 'religion',
58
+ 'space',
59
+ 'sports',
60
+ 'statistics',
61
+ 'trivia',
62
+ 'tv'
63
+ ])
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,80 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'random_facts' # and any other gems you need
5
+ require 'json'
6
+
7
+ RSpec.configure do |config|
8
+ # rspec-expectations config goes here. You can use an alternate
9
+ # assertion/expectation library such as wrong or the stdlib/minitest
10
+ # assertions if you prefer.
11
+ config.expect_with :rspec do |expectations|
12
+ # This option will default to `true` in RSpec 4. It makes the `description`
13
+ # and `failure_message` of custom matchers include text for helper methods
14
+ # defined using `chain`, e.g.:
15
+ # be_bigger_than(2).and_smaller_than(4).description
16
+ # # => "be bigger than 2 and smaller than 4"
17
+ # ...rather than:
18
+ # # => "be bigger than 2"
19
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20
+ end
21
+
22
+ # rspec-mocks config goes here. You can use an alternate test double
23
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
24
+ config.mock_with :rspec do |mocks|
25
+ # Prevents you from mocking or stubbing a method that does not exist on
26
+ # a real object. This is generally recommended, and will default to
27
+ # `true` in RSpec 4.
28
+ mocks.verify_partial_doubles = true
29
+ end
30
+
31
+ # The settings below are suggested to provide a good initial experience
32
+ # with RSpec, but feel free to customize to your heart's content.
33
+ =begin
34
+ # These two settings work together to allow you to limit a spec run
35
+ # to individual examples or groups you care about by tagging them with
36
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
37
+ # get run.
38
+ config.filter_run :focus
39
+ config.run_all_when_everything_filtered = true
40
+
41
+ # Allows RSpec to persist some state between runs in order to support
42
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
43
+ # you configure your source control system to ignore this file.
44
+ config.example_status_persistence_file_path = "spec/examples.txt"
45
+
46
+ # Limits the available syntax to the non-monkey patched syntax that is
47
+ # recommended. For more details, see:
48
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
49
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
50
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
51
+ config.disable_monkey_patching!
52
+
53
+ # Many RSpec users commonly either run the entire suite or an individual
54
+ # file, and it's useful to allow more verbose output when running an
55
+ # individual spec file.
56
+ if config.files_to_run.one?
57
+ # Use the documentation formatter for detailed output,
58
+ # unless a formatter has already been configured
59
+ # (e.g. via a command-line flag).
60
+ config.default_formatter = 'doc'
61
+ end
62
+
63
+ # Print the 10 slowest examples and example groups at the
64
+ # end of the spec run, to help surface which specs are running
65
+ # particularly slow.
66
+ config.profile_examples = 10
67
+
68
+ # Run specs in random order to surface order dependencies. If you find an
69
+ # order dependency and want to debug it, you can fix the order by providing
70
+ # the seed, which is printed after each run.
71
+ # --seed 1234
72
+ config.order = :random
73
+
74
+ # Seed global randomization in this process using the `--seed` CLI option.
75
+ # Setting this allows you to use `--seed` to deterministically reproduce
76
+ # test failures related to randomization by passing the same `--seed` value
77
+ # as the one that triggered the failure.
78
+ Kernel.srand config.seed
79
+ =end
80
+ end