fact_is_fact 1.0.0 → 1.1.1
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 +4 -4
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +88 -5
- data/lib/fact_is_fact.rb +3 -2
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7fcc04684ad58972db23d324bfa82a35d2f77f04b1293e691058832900fd28a9
|
|
4
|
+
data.tar.gz: 14d52d4b72e2286edfac1b2ca1f4769db168041ed1b61e25c8d6252ab7385b85
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8a419e7ee87fb12a3427eebe68aac249ae5506dd6d52679551ae06555e2382298b1f30caf0eabef9e3dec6a7f5966d524f67330e92ee46fa1b348faefaa64cb
|
|
7
|
+
data.tar.gz: a527e9434408979a75f7e41af308da05669d804a1242f3936ccb5b91792883c66b621538b7896272047fe3d25f876f9b36edba2a4cdb82de2a79877d1a0df4bf
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
## Version 1.1.0
|
|
2
|
+
Ability to pass optional params with the request
|
|
3
|
+
|
|
1
4
|
## Version 1.0.0
|
|
2
|
-
Deprecating the old way 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.
|
|
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.
|
|
3
6
|
|
|
4
7
|
## Version 0.31.1
|
data/Gemfile.lock
CHANGED
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
|
data/lib/fact_is_fact.rb
CHANGED
|
@@ -5,10 +5,11 @@ class FactIsFact
|
|
|
5
5
|
TYPE = %w[trivia math year date].freeze
|
|
6
6
|
|
|
7
7
|
class << self
|
|
8
|
-
def return(type:, number
|
|
8
|
+
def return(type:, number:, **options)
|
|
9
9
|
return 'not a valid type' unless TYPE.include?(type)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
query_params = URI.encode_www_form(options)
|
|
12
|
+
number_facts_uri = URI("#{BASE_URI}/#{number}/#{type}?#{query_params}")
|
|
12
13
|
Net::HTTP.get(number_facts_uri)
|
|
13
14
|
end
|
|
14
15
|
end
|
data/lib/version.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '1.
|
|
1
|
+
VERSION = '1.1.1'.freeze
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fact_is_fact
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
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-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|