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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc48d93a01e894b9d9bfb586b5d746b280d9442eba9fb8ca98aed3cf4929ba9b
4
- data.tar.gz: a7cf16c34b44a82b7452e27f3904f29bff439da81c25e1c39602f3aaa549dcd1
3
+ metadata.gz: 7fcc04684ad58972db23d324bfa82a35d2f77f04b1293e691058832900fd28a9
4
+ data.tar.gz: 14d52d4b72e2286edfac1b2ca1f4769db168041ed1b61e25c8d6252ab7385b85
5
5
  SHA512:
6
- metadata.gz: 48d51934ae5b2aa3c6e887b4c8f39665872875b2adbc98d8896d8b37ccd6579c52c427f5a70b425abd439845c360248383c025aa3cf15a137108aed7e27559c9
7
- data.tar.gz: ace65547c7f70afab343ce5bbada2347b2ee176a2735b6e63146534dc096cf212ce857281220db78227d6d4ebe33c03c6c5955ec61ba24a934cdb0b19a86913c
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fact_is_fact (1.0.0)
4
+ fact_is_fact (1.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 `numbersapi.com` to return the results.
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
- Currently it only supports Random trivia about a number.
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::Random.new(number: 42).trivia
28
- #=> "42 is the answer to the Ultimate Question of Life, the Universe, and Everything."
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
- number_facts_uri = URI("#{BASE_URI}/#{number}/#{type}")
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.0.0'.freeze
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.0.0
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: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2021-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler