haar_joke 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 850926d8886841be7f7ba33a407fe7bca2caf014
4
+ data.tar.gz: f6cee45d0fdac24e6e1c43eccf6fb89b3d30ddca
5
+ SHA512:
6
+ metadata.gz: f6677a849fdb20c4c4af699c83b2913168da9fa310d83a9655d24dfc455a26d0276c12a331c73e4710dba486a2365a5fb1fef58509801d275033d393cadc581d
7
+ data.tar.gz: b0ad431fcbdbb73cb37ad0c2b88dac4650c9fbeb4204f12b78c7e34a8499564fd9eb9ee06cb101d30c6722476c44016b14d73c9d2cd07bbcf00bedaa607ffcae
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.gem/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haarjoke.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gemma Gotch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # HaarJoke
2
+
3
+ <img src="https://travis-ci.org/pveggie/haarjoke.svg?branch=master">
4
+
5
+ HaarJoke can be used to create Chuck Norris type jokes featuring Haar.
6
+
7
+ <img src="http://vignette2.wikia.nocookie.net/fireemblem/images/f/fb/Haar.jpg/revision/latest?cb=20090813131313">
8
+
9
+ * Haar is a character from Fire Emblem: Path of Radiance and Fire Emblem:
10
+ Radiant Dawn. He is know for being badass even while sleeping. Haar does not
11
+ kill enemies; enemies kill themselves on Haar.
12
+
13
+ <a href="http://www.gamefaqs.com/boards/932999-fire-emblem-radiant-dawn/41201620">http://www.gamefaqs.com/boards/932999-fire-emblem-radiant-dawn/41201620</a>
14
+
15
+ Jokes are taken from The Internet Chuck Norris Database
16
+ <a href="http://www.icndb.com/api/">(http://www.icndb.com/api/)</a>
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'haar_joke'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install haar_joke
33
+
34
+ ## Usage
35
+
36
+ You can generate a default Haar joke.
37
+
38
+ ```ruby
39
+ HaarJoke.create_joke
40
+ ```
41
+
42
+ You can also customise the joke to feature someone other than Haar,
43
+ to substitute terms of your choice, and to filter out jokes based on terms.
44
+
45
+ ```ruby
46
+ HaarJoke.create_custom_joke
47
+ ```
48
+
49
+ This requires a YAML file listing filters and substituions at
50
+ config/haar_joke.yml
51
+
52
+ Example (No jokes about milk. Chuck Norris to be replaced by Brian):
53
+ ```yaml
54
+ filters:
55
+ - milk
56
+ substitutions:
57
+ chuck norrises: Brians
58
+ chuck norris': Brian's
59
+ chuck norris: Brian
60
+ ```
61
+
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pveggie/haarjoke.
72
+
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
77
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'haar_joke'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/haar_joke.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haar_joke/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'haar_joke'
8
+ spec.version = HaarJoke::VERSION
9
+ spec.authors = ['Gemma Gotch']
10
+ spec.email = ['pveggie@hotmail.com']
11
+
12
+ spec.summary = 'Returns a joke based on a Chuck Norris joke but
13
+ featuring Haar.'
14
+ spec.description = 'Uses the Chuck Norris joke api and replaces Chuck
15
+ Norris with the Fire Emblem character Haar.'
16
+ spec.homepage = 'https://github.com/pveggie/haarjoke'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set
20
+ # the 'allowed_push_host' to allow pushing to a single host or delete
21
+ # this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against
26
+ public gem pushes.'
27
+ end
28
+
29
+ spec.files = `git ls-files -z`
30
+ .split("\x0")
31
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.12'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'webmock', '~> 2.1'
40
+ end
@@ -0,0 +1,34 @@
1
+ # jokes containing terms from the filters list will not be used
2
+ filters:
3
+ # Add or remove filters as required.
4
+ - race
5
+ - woman
6
+ - women
7
+ - gay
8
+ - black
9
+ - natives
10
+ - porn
11
+ - handicap
12
+ - god
13
+ - bible
14
+ - staring
15
+ - rape
16
+ - condom
17
+
18
+ # subsitutions is a list of terms that will be replaced with other terms
19
+ substitutions:
20
+ # Add or remove subsitutions as required. Be careful about the order.
21
+ # e.g. substituting "america" first would change "american" to "daeinn"
22
+ chuck norrises: Haars
23
+ chuck norris': Haar's
24
+ chuck norris: Haar
25
+ penis: axe
26
+ dick: axe
27
+ american: Daein
28
+ america: Daein
29
+ beat: sleep
30
+ superman: Chuck Norris
31
+ beard: eyepatch
32
+ pick-up truck: wyvern
33
+ pick-up: wyvern
34
+ walk: fly
@@ -0,0 +1,46 @@
1
+ module HaarJoke
2
+ # This class can be used to create joke instances. The .text method
3
+ # returns the joke text.
4
+ class Joke
5
+ attr_reader :text
6
+
7
+ def text
8
+ @text = generate_joke
9
+ end
10
+
11
+ private
12
+
13
+ def generate_joke
14
+ joke = joke_from_api
15
+ !joke.nil? ? substitute_terms(joke) : 'Zzzzzzzzzzzzzzz. Haar is sleeping.'
16
+ end
17
+
18
+ def joke_from_api
19
+ api_url = 'http://api.icndb.com/jokes/random'
20
+ joke = ''
21
+
22
+ open(api_url) do |stream|
23
+ joke = JSON.parse(stream.read)
24
+ end
25
+
26
+ joke = joke['value']['joke']
27
+ accept_joke?(joke) ? joke : joke_from_api
28
+
29
+ rescue StandardError
30
+ nil
31
+ end
32
+
33
+ def accept_joke?(joke)
34
+ filters = HaarJoke.config['filters'].join('|')
35
+ joke.match(/#{filters}/i).nil?
36
+ end
37
+
38
+ def substitute_terms(joke)
39
+ substitutions = HaarJoke.config['substitutions']
40
+ substitutions.each do |key, value|
41
+ joke.gsub!(/#{key}/i, value)
42
+ end
43
+ joke
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module HaarJoke
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/haar_joke.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'haar_joke/version'
2
+ require 'haar_joke/joke'
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'yaml'
6
+
7
+ # This module contains a Joke class for creating jokes featuring the fire
8
+ # Emblem Haar (using Chuck Norris jokes from http://api.icndb.com).
9
+ # It also contains a method for creating a joke and getting returning the joke
10
+ module HaarJoke
11
+ # load default filters and substitutions
12
+ file_path = File.join(File.dirname(__FILE__), 'haar_joke/haar_joke.yml')
13
+ @config = YAML.load_file(file_path)
14
+
15
+ # user can create joke with custom settings
16
+ def self.create_joke
17
+ joke = Joke.new
18
+ joke.text
19
+ end
20
+
21
+ # user can create joke with their own file
22
+ def self.create_custom_joke
23
+ @config = use_custom_file
24
+ create_joke
25
+ end
26
+
27
+ private
28
+
29
+ def self.use_custom_file
30
+ file_path = Rails.root.join('config/haar_joke.yml')
31
+ YAML.load_file(file_path)
32
+ rescue
33
+ raise 'YAML file missing. Custom method requires a config/haar_joke.yml
34
+ file. For non custom jokes, use HaarJoke.create_joke'
35
+ end
36
+
37
+ def self.config
38
+ @config
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haar_joke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gemma Gotch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ description: |-
70
+ Uses the Chuck Norris joke api and replaces Chuck
71
+ Norris with the Fire Emblem character Haar.
72
+ email:
73
+ - pveggie@hotmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - haar_joke.gemspec
88
+ - lib/haar_joke.rb
89
+ - lib/haar_joke/haar_joke.yml
90
+ - lib/haar_joke/joke.rb
91
+ - lib/haar_joke/version.rb
92
+ homepage: https://github.com/pveggie/haarjoke
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Returns a joke based on a Chuck Norris joke but featuring Haar.
117
+ test_files: []