fact_is_fact 0.1.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
- SHA1:
3
- metadata.gz: fa3e4ac2b219d65a50ddca4c0f8f6d634af53d14
4
- data.tar.gz: c1d090947956d48fe5d80843a30191a7a52d527b
2
+ SHA256:
3
+ metadata.gz: 7fcc04684ad58972db23d324bfa82a35d2f77f04b1293e691058832900fd28a9
4
+ data.tar.gz: 14d52d4b72e2286edfac1b2ca1f4769db168041ed1b61e25c8d6252ab7385b85
5
5
  SHA512:
6
- metadata.gz: 312b9d9adf9beaabd677335c488357a35a7f4d1530808a52463a99597fbcea516cc2938913f4e59b35d9569f468e19d5fafd05988be13cfad3737091125eb988
7
- data.tar.gz: 07cc992a15097305fdc574089afc4053c15ba359e1dd094fa5bd5c11498515dfc42d58746d3ee9c1ab121ae88de5fe89aa7a1a5ca793926935eb48d6a534bfbd
6
+ metadata.gz: e8a419e7ee87fb12a3427eebe68aac249ae5506dd6d52679551ae06555e2382298b1f30caf0eabef9e3dec6a7f5966d524f67330e92ee46fa1b348faefaa64cb
7
+ data.tar.gz: a527e9434408979a75f7e41af308da05669d804a1242f3936ccb5b91792883c66b621538b7896272047fe3d25f876f9b36edba2a4cdb82de2a79877d1a0df4bf
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 (0.1.0)
4
+ fact_is_fact (1.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.3)
10
- minitest (5.11.3)
11
- rake (10.5.0)
9
+ diff-lcs (1.4.4)
10
+ rake (13.0.1)
12
11
  rspec (3.8.0)
13
12
  rspec-core (~> 3.8.0)
14
13
  rspec-expectations (~> 3.8.0)
15
14
  rspec-mocks (~> 3.8.0)
16
- rspec-core (3.8.1)
15
+ rspec-core (3.8.2)
17
16
  rspec-support (~> 3.8.0)
18
- rspec-expectations (3.8.4)
17
+ rspec-expectations (3.8.6)
19
18
  diff-lcs (>= 1.2.0, < 2.0)
20
19
  rspec-support (~> 3.8.0)
21
- rspec-mocks (3.8.1)
20
+ rspec-mocks (3.8.2)
22
21
  diff-lcs (>= 1.2.0, < 2.0)
23
22
  rspec-support (~> 3.8.0)
24
- rspec-support (3.8.2)
23
+ rspec-support (3.8.3)
25
24
 
26
25
  PLATFORMS
27
26
  ruby
28
27
 
29
28
  DEPENDENCIES
30
- bundler (~> 1.17)
29
+ bundler (= 2.1.4)
31
30
  fact_is_fact!
32
- minitest (~> 5.0)
33
- rake (~> 10.0)
31
+ rake (~> 13.0)
34
32
  rspec (~> 3.8.0)
35
33
 
36
34
  BUNDLED WITH
37
- 1.17.2
35
+ 2.1.4
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # FactIsFact
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fact_is_fact`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem returns a fact about any number provided. It is useful when you want
4
+ some random trivia or facts to be displayed about a number, on your website.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ P.S: Gem internally uses http://numbersapi.com/ to return the results.
6
7
 
7
8
  ## Installation
8
9
 
@@ -21,8 +22,94 @@ Or install it yourself as:
21
22
  $ gem install fact_is_fact
22
23
 
23
24
  ## Usage
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`
24
30
 
25
- TODO: Write usage instructions here
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
+
109
+ ```ruby
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."
112
+ ```
26
113
 
27
114
  ## Development
28
115
 
@@ -32,7 +119,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
119
 
33
120
  ## Contributing
34
121
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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.
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.
36
123
 
37
124
  ## License
38
125
 
data/fact_is_fact.gemspec CHANGED
@@ -1,27 +1,25 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
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 = "fact_is_fact"
8
- spec.version = FactIsFact::VERSION
9
- spec.authors = ["Aks"]
10
- spec.email = ["abhinay302@gmail.com"]
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 = %q{Stating the fact with ease}
13
- spec.description = %q{library helps you display random facts}
14
- spec.homepage = "https://github.com/abhinaykumar/fact_is_fact"
15
- spec.license = "MIT"
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["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://github.com/abhinaykumar/fact_is_fact"
24
- spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
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', '~> 1.17'
40
- spec.add_development_dependency 'minitest', '~> 5.0'
41
- spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'bundler', '2.1.4'
38
+ spec.add_development_dependency 'rake', '~> 13.0'
42
39
  spec.add_development_dependency 'rspec', '~> 3.8.0'
43
40
  end
data/lib/fact_is_fact.rb CHANGED
@@ -1,8 +1,18 @@
1
- require 'fact_is_fact/version'
1
+ require 'net/http'
2
2
 
3
- module FactIsFact
4
- require 'net/http'
5
- require 'fact_is_fact/random'
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.1.1'.freeze
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fact_is_fact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Aks
7
+ - Abhinay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-14 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.17'
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
- - - "~>"
24
+ - - '='
39
25
  - !ruby/object:Gem::Version
40
- version: '5.0'
26
+ version: 2.1.4
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: '10.0'
33
+ version: '13.0'
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: '10.0'
40
+ version: '13.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +52,7 @@ dependencies:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
54
  version: 3.8.0
69
- description: library helps you display random facts
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/fact_is_fact/random.rb
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: Put your gem's CHANGELOG.md URL here.
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
- rubyforge_project:
114
- rubygems_version: 2.5.2.2
99
+ rubygems_version: 3.1.2
115
100
  signing_key:
116
101
  specification_version: 4
117
- summary: Stating the fact with ease
102
+ summary: This gem allows users to get a random trivia about a number or date or a
103
+ year
118
104
  test_files: []
@@ -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
@@ -1,3 +0,0 @@
1
- module FactIsFact
2
- VERSION = "0.1.0"
3
- end