fact_is_fact 0.2.0 → 1.2.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 +5 -5
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +19 -21
- data/README.md +89 -6
- data/fact_is_fact.gemspec +16 -19
- data/lib/fact_is_fact.rb +14 -4
- data/lib/version.rb +1 -0
- metadata +22 -36
- data/lib/fact_is_fact/random.rb +0 -15
- data/lib/fact_is_fact/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 69a0dd40312fe67715cc1fb0c320a5817af3ef1a91ad418dd3eb853bad7b38f3
|
|
4
|
+
data.tar.gz: fc2349cf4821ee2d9dc2102252efde16125b9571cd55b14f0f5341c803fcde2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e707f597b4de921eef72a66fe82a3b1f11081ad4cbb2d0d03a21a1724658bc187e3fe992824b628b5ca6a3df1559b7ce2d98891600e9d5c7e109437508e4a753
|
|
7
|
+
data.tar.gz: cdf18cdb1d573a465f8654c7e57d46d38efd5bcffee594bf0b1d39a060e5573dac0a2a3b6b80b0973a9f1b9578bb035fce4e104b026e4c3e6541b0ed51d36412
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
## Version 1.1.0
|
|
2
|
+
Ability to pass optional params with the request
|
|
3
|
+
|
|
4
|
+
## Version 1.0.0
|
|
5
|
+
Deprecating the old way of calling the class method. With this version, you will be able to get trivia, math, year and date facts about the any number of a day.
|
|
6
|
+
|
|
7
|
+
## Version 0.31.1
|
data/Gemfile.lock
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fact_is_fact (
|
|
4
|
+
fact_is_fact (1.2.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
diff-lcs (1.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
rspec-
|
|
14
|
-
rspec-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
rspec-expectations (3.8.4)
|
|
9
|
+
diff-lcs (1.4.4)
|
|
10
|
+
rake (13.0.3)
|
|
11
|
+
rspec (3.10.0)
|
|
12
|
+
rspec-core (~> 3.10.0)
|
|
13
|
+
rspec-expectations (~> 3.10.0)
|
|
14
|
+
rspec-mocks (~> 3.10.0)
|
|
15
|
+
rspec-core (3.10.1)
|
|
16
|
+
rspec-support (~> 3.10.0)
|
|
17
|
+
rspec-expectations (3.10.1)
|
|
19
18
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
20
|
-
rspec-support (~> 3.
|
|
21
|
-
rspec-mocks (3.
|
|
19
|
+
rspec-support (~> 3.10.0)
|
|
20
|
+
rspec-mocks (3.10.2)
|
|
22
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
23
|
-
rspec-support (~> 3.
|
|
24
|
-
rspec-support (3.
|
|
22
|
+
rspec-support (~> 3.10.0)
|
|
23
|
+
rspec-support (3.10.2)
|
|
25
24
|
|
|
26
25
|
PLATFORMS
|
|
27
|
-
|
|
26
|
+
x86_64-darwin-19
|
|
28
27
|
|
|
29
28
|
DEPENDENCIES
|
|
30
|
-
bundler (
|
|
29
|
+
bundler (>= 2.2.17)
|
|
31
30
|
fact_is_fact!
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
rspec (~> 3.8.0)
|
|
31
|
+
rake (= 13.0.3)
|
|
32
|
+
rspec (= 3.10.0)
|
|
35
33
|
|
|
36
34
|
BUNDLED WITH
|
|
37
|
-
|
|
35
|
+
2.2.17
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# FactIsFact
|
|
2
2
|
|
|
3
|
-
This gem returns a fact about any number provided. It is useful when you want
|
|
3
|
+
This gem returns a fact about any number provided. It is useful when you want
|
|
4
4
|
some random trivia or facts to be displayed about a number, on your website.
|
|
5
5
|
|
|
6
|
-
P.S: Gem internally uses
|
|
6
|
+
P.S: Gem internally uses http://numbersapi.com/ to return the results.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -22,10 +22,93 @@ Or install it yourself as:
|
|
|
22
22
|
$ gem install fact_is_fact
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
|
-
|
|
25
|
+
* `type` is one of `trivia`, `math`, `date`, or `year`. Defaults to `trivia` if omitted.
|
|
26
|
+
* `number` is
|
|
27
|
+
* an `integer`, or
|
|
28
|
+
* the keyword `random`, for which we will try to return a random available fact, or
|
|
29
|
+
* a `day` of year in the form `month/day` (eg. 2/29, 1/09, 04/1), if `type` is `date`
|
|
30
|
+
|
|
31
|
+
basic examples
|
|
32
|
+
```ruby
|
|
33
|
+
# math fact
|
|
34
|
+
FactIsFact.return(type: 'math', number: '1234')
|
|
35
|
+
#=> "1234 is the smallest 4-digit number with increasing digits."
|
|
36
|
+
|
|
37
|
+
# date fact
|
|
38
|
+
FactIsFact.return(type: 'date', number: '2/29')
|
|
39
|
+
#=> "February 29th is the day in 1892 that St. Petersburg, Florida is incorporated."
|
|
40
|
+
|
|
41
|
+
# year fact
|
|
42
|
+
FactIsFact.return(type: 'year', number: '1234')
|
|
43
|
+
#=> "1234 is the year that the Manden region raises against the Kaniaga kingdom."
|
|
44
|
+
|
|
45
|
+
# trivia
|
|
46
|
+
FactIsFact.return(type: 'trivia', number: 'random')
|
|
47
|
+
#=> "150000000 is the number of items held in the British Library."
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Optional parameters
|
|
51
|
+
|
|
52
|
+
### Result in JSON format
|
|
53
|
+
Include the query parameter `json` or set the HTTP header `Content-Type` to `application/json` to return the fact and associated meta-data as a JSON object
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
FactIsFact.return(type: 'math', number: '123', json: '')
|
|
57
|
+
#=> "{\n \"text\": \"123 is the 10^{th} Lucas number.\",\n \"number\": 123,\n \"found\": true,\n \"type\": \"math\"\n}"
|
|
58
|
+
|
|
59
|
+
FactIsFact.return(type: 'trivia', number: 'random', json: true)
|
|
60
|
+
#=> "{\n \"text\": \"88 is the number of keys on a piano (36 black and 52 white).\",\n \"number\": 88,\n \"found\": true,\n \"type\": \"trivia\"\n}"
|
|
61
|
+
|
|
62
|
+
FactIsFact.return(type: 'math', number: '12', json: nil)
|
|
63
|
+
#=> "{\n \"text\": \"12 is a superfactorial, being the product of the first three factorials.\",\n \"number\": 12,\n \"found\": true,\n \"type\": \"math\"\n}"
|
|
64
|
+
```
|
|
65
|
+
**Note**: you can pass any value to `json`, as long as the parameter is present, it does not matter what the value of the `json` parameter is.
|
|
66
|
+
|
|
67
|
+
### FRAGMENT
|
|
68
|
+
Return the fact as a sentence fragment that can be easily included as part of a larger sentence. This means that the first word is lowercase and ending punctuation is omitted. For trivia and math, a noun phrase is returned that can be used in a sentence like "We now have more users than [fact as fragment]!".
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
FactIsFact.return(type: 'math', number: '13', fragment: '')
|
|
72
|
+
#=> "the number of Archimedian solids"
|
|
73
|
+
|
|
74
|
+
FactIsFact.return(type: 'math', number: '139', fragment: nil)
|
|
75
|
+
#=> "the number of unlabeled topologies with 5 elements"
|
|
76
|
+
|
|
77
|
+
FactIsFact.return(type: 'year', number: '1920', fragment: true)
|
|
78
|
+
#=> "the United States Congress refuses to ratify the Treaty of Versailles"
|
|
79
|
+
```
|
|
80
|
+
**Note**: you can pass any value to `fragment`, as long as the parameter is present, it does not matter what the value of the `fragment` parameter is.
|
|
81
|
+
|
|
82
|
+
### Not Found
|
|
83
|
+
The `notfound` field tells us what to do if the number is not found. You can give us
|
|
84
|
+
|
|
85
|
+
* `floor` to round down to the largest number that does have an associated fact, and return that fact.
|
|
86
|
+
```ruby
|
|
87
|
+
FactIsFact.return(type: 'math', number: '123123123', notfound: 'floor')
|
|
88
|
+
#=> "12988816 is the number of domino tilings of an 8\xC3\x978 checkerboard."
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
* `ceil`, which is like `floor` but rounds up to the smallest number that has an associated fact.
|
|
92
|
+
```ruby
|
|
93
|
+
FactIsFact.return(type: 'math', number: '123123123', notfound: 'ceil')
|
|
94
|
+
#=> "215000000 is the number of mathematical constants are collected on the Plouffe's Inverter as of 2010."
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Default message (if notfound)
|
|
98
|
+
|
|
99
|
+
* `default` to return one of our pre-written missing messages, or a message you supply with the default query field. This is the default behaviour.
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
FactIsFact.return(type: 'math', number: '123123123', default: 'no facts found')
|
|
103
|
+
#=> "no facts found"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## MIN AND MAX
|
|
107
|
+
Restrict the range of values returned to the inclusive range [min, max] when random is given as the number.
|
|
108
|
+
|
|
26
109
|
```ruby
|
|
27
|
-
FactIsFact
|
|
28
|
-
#=> "
|
|
110
|
+
FactIsFact.return(type: 'trivia', number: 'random', min: 10, max: 20)
|
|
111
|
+
#=> "16 is the number of personality types in the Myers-Briggs classification system."
|
|
29
112
|
```
|
|
30
113
|
|
|
31
114
|
## Development
|
|
@@ -36,7 +119,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
36
119
|
|
|
37
120
|
## Contributing
|
|
38
121
|
|
|
39
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
122
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abhinaykumar/fact_is_fact. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
40
123
|
|
|
41
124
|
## License
|
|
42
125
|
|
data/fact_is_fact.gemspec
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require "fact_is_fact/version"
|
|
1
|
+
require './lib/fact_is_fact'
|
|
2
|
+
require './lib/version'
|
|
5
3
|
|
|
6
4
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
8
|
-
spec.version =
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
5
|
+
spec.name = 'fact_is_fact'
|
|
6
|
+
spec.version = VERSION
|
|
7
|
+
spec.authors = ['Abhinay']
|
|
8
|
+
spec.email = ['abhinay302@gmail.com']
|
|
11
9
|
|
|
12
|
-
spec.summary =
|
|
13
|
-
spec.description =
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.license =
|
|
10
|
+
spec.summary = 'This gem allows users to get a random trivia about a number or date or a year'
|
|
11
|
+
spec.description = 'library helps you display random facts about a number or date or a year.'
|
|
12
|
+
spec.homepage = 'https://github.com/abhinaykumar/fact_is_fact'
|
|
13
|
+
spec.license = 'MIT'
|
|
16
14
|
|
|
17
15
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
16
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
17
|
if spec.respond_to?(:metadata)
|
|
20
18
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
21
19
|
|
|
22
|
-
spec.metadata[
|
|
23
|
-
spec.metadata[
|
|
24
|
-
spec.metadata[
|
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/abhinaykumar/fact_is_fact'
|
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/abhinaykumar/fact_is_fact/blob/master/CHANGELOG.md'
|
|
25
23
|
else
|
|
26
24
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
27
25
|
"public gem pushes."
|
|
@@ -36,8 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
36
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
37
35
|
spec.require_paths = ["lib"]
|
|
38
36
|
|
|
39
|
-
spec.add_development_dependency 'bundler', '
|
|
40
|
-
spec.add_development_dependency '
|
|
41
|
-
spec.add_development_dependency '
|
|
42
|
-
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
|
37
|
+
spec.add_development_dependency 'bundler', '>= 2.2.17'
|
|
38
|
+
spec.add_development_dependency 'rake', '13.0.3'
|
|
39
|
+
spec.add_development_dependency 'rspec', '3.10.0'
|
|
43
40
|
end
|
data/lib/fact_is_fact.rb
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'net/http'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
class FactIsFact
|
|
4
|
+
BASE_URI = 'http://numbersapi.com'.freeze
|
|
5
|
+
TYPE = %w[trivia math year date].freeze
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def return(type:, number:, **options)
|
|
9
|
+
return 'not a valid type' unless TYPE.include?(type)
|
|
10
|
+
|
|
11
|
+
query_params = URI.encode_www_form(options)
|
|
12
|
+
number_facts_uri = URI("#{BASE_URI}/#{number}/#{type}?#{query_params}")
|
|
13
|
+
Net::HTTP.get(number_facts_uri)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
6
16
|
|
|
7
17
|
class Error < StandardError; end
|
|
8
18
|
end
|
data/lib/version.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = '1.2.0'.freeze
|
metadata
CHANGED
|
@@ -1,72 +1,58 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fact_is_fact
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Abhinay
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 2.2.17
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: minitest
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '5.0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '5.0'
|
|
26
|
+
version: 2.2.17
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
28
|
name: rake
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
|
44
30
|
requirements:
|
|
45
|
-
- -
|
|
31
|
+
- - '='
|
|
46
32
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
33
|
+
version: 13.0.3
|
|
48
34
|
type: :development
|
|
49
35
|
prerelease: false
|
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
37
|
requirements:
|
|
52
|
-
- -
|
|
38
|
+
- - '='
|
|
53
39
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
40
|
+
version: 13.0.3
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: rspec
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
58
44
|
requirements:
|
|
59
|
-
- -
|
|
45
|
+
- - '='
|
|
60
46
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 3.
|
|
47
|
+
version: 3.10.0
|
|
62
48
|
type: :development
|
|
63
49
|
prerelease: false
|
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
51
|
requirements:
|
|
66
|
-
- -
|
|
52
|
+
- - '='
|
|
67
53
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 3.
|
|
69
|
-
description: library helps you display random facts
|
|
54
|
+
version: 3.10.0
|
|
55
|
+
description: library helps you display random facts about a number or date or a year.
|
|
70
56
|
email:
|
|
71
57
|
- abhinay302@gmail.com
|
|
72
58
|
executables: []
|
|
@@ -75,6 +61,7 @@ extra_rdoc_files: []
|
|
|
75
61
|
files:
|
|
76
62
|
- ".gitignore"
|
|
77
63
|
- ".travis.yml"
|
|
64
|
+
- CHANGELOG.md
|
|
78
65
|
- CODE_OF_CONDUCT.md
|
|
79
66
|
- Gemfile
|
|
80
67
|
- Gemfile.lock
|
|
@@ -85,8 +72,7 @@ files:
|
|
|
85
72
|
- bin/setup
|
|
86
73
|
- fact_is_fact.gemspec
|
|
87
74
|
- lib/fact_is_fact.rb
|
|
88
|
-
- lib/
|
|
89
|
-
- lib/fact_is_fact/version.rb
|
|
75
|
+
- lib/version.rb
|
|
90
76
|
homepage: https://github.com/abhinaykumar/fact_is_fact
|
|
91
77
|
licenses:
|
|
92
78
|
- MIT
|
|
@@ -94,7 +80,7 @@ metadata:
|
|
|
94
80
|
allowed_push_host: https://rubygems.org
|
|
95
81
|
homepage_uri: https://github.com/abhinaykumar/fact_is_fact
|
|
96
82
|
source_code_uri: https://github.com/abhinaykumar/fact_is_fact
|
|
97
|
-
changelog_uri:
|
|
83
|
+
changelog_uri: https://github.com/abhinaykumar/fact_is_fact/blob/master/CHANGELOG.md
|
|
98
84
|
post_install_message:
|
|
99
85
|
rdoc_options: []
|
|
100
86
|
require_paths:
|
|
@@ -110,9 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
96
|
- !ruby/object:Gem::Version
|
|
111
97
|
version: '0'
|
|
112
98
|
requirements: []
|
|
113
|
-
|
|
114
|
-
rubygems_version: 2.5.2.2
|
|
99
|
+
rubygems_version: 3.1.2
|
|
115
100
|
signing_key:
|
|
116
101
|
specification_version: 4
|
|
117
|
-
summary:
|
|
102
|
+
summary: This gem allows users to get a random trivia about a number or date or a
|
|
103
|
+
year
|
|
118
104
|
test_files: []
|
data/lib/fact_is_fact/random.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module FactIsFact
|
|
2
|
-
class Random
|
|
3
|
-
|
|
4
|
-
def initialize(args)
|
|
5
|
-
@number = args[:number] || 'random'
|
|
6
|
-
@fact_type = args[:fact_type]
|
|
7
|
-
@base_uri = 'http://numbersapi.com'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def trivia
|
|
11
|
-
number_facts_uri = URI("#{@base_uri}/#{@number}/#{@fact_type}")
|
|
12
|
-
Net::HTTP.get(number_facts_uri)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/fact_is_fact/version.rb
DELETED