fandom-word 0.3.0 → 0.4.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 +4 -4
- data/.gitattributes +5 -0
- data/.gitignore +3 -1
- data/.rspec +3 -0
- data/.rubocop.yml +16 -1
- data/.travis.yml +7 -0
- data/.yardoc/checksums +5 -0
- data/.yardoc/complete +0 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile +18 -2
- data/README.md +15 -11
- data/Rakefile +61 -7
- data/data/words.data +0 -0
- data/doc/FandomWord.html +347 -0
- data/doc/FandomWord/FandomRandomizer.html +419 -0
- data/doc/FandomWord/FandomWordCatalog.html +424 -0
- data/doc/FandomWord/Fandoms.html +617 -0
- data/doc/_index.html +128 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +492 -0
- data/doc/file.README.html +121 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +121 -0
- data/doc/js/app.js +248 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +123 -0
- data/doc/top-level-namespace.html +110 -0
- data/fandom-word.gemspec +3 -3
- data/lib/fandom_word.rb +61 -17
- data/lib/fandom_word_catalog.rb +4 -1
- data/lib/fandoms.rb +43 -6
- data/lib/version.rb +2 -1
- metadata +30 -4
data/fandom-word.gemspec
CHANGED
@@ -5,11 +5,11 @@ require 'version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'fandom-word'
|
7
7
|
spec.version = FandomWord::VERSION
|
8
|
-
spec.date =
|
8
|
+
spec.date = Date.today.to_s
|
9
9
|
spec.summary = 'Fandom Word'
|
10
|
-
spec.description = '
|
10
|
+
spec.description = 'A fandom word generator that returns random words from various fandoms.'
|
11
11
|
spec.authors = ['Ravi Nath', 'Manni Reyes']
|
12
|
-
spec.email = %w[majindm24@gmail.com manni@
|
12
|
+
spec.email = %w[majindm24@gmail.com manni.reies@gmail.com]
|
13
13
|
spec.files = `git ls-files`
|
14
14
|
.split($RS)
|
15
15
|
.reject { |file| file.match(/^(spec|word-lists|build)/) }
|
data/lib/fandom_word.rb
CHANGED
@@ -1,53 +1,97 @@
|
|
1
|
-
#
|
1
|
+
# Holds all classes and methods for Fandom Word
|
2
2
|
module FandomWord
|
3
3
|
require 'singleton'
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
6
|
+
# Returns random word from any fandom in catalog. Fandom category can be specified.
|
7
|
+
#
|
8
|
+
# @param [String, Array] fandom_name_or_names Fandom category or array of categories
|
9
|
+
# @return [String] Random word
|
10
|
+
def random_word(fandom_name_or_names = nil)
|
11
|
+
if fandom_name_or_names
|
12
|
+
FandomRandomizer.instance.random_word fandom_name_or_names
|
13
|
+
else
|
14
|
+
FandomRandomizer.instance.random_word
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
|
18
|
+
# Returns the list of fandoms (categories)
|
19
|
+
def fandoms
|
20
|
+
FandomRandomizer.instance.available_fandoms
|
12
21
|
end
|
13
22
|
end
|
14
23
|
|
15
|
-
#
|
24
|
+
# Provides singleton interface with fandom word catalog to allow retrieval of random words, random words based on
|
25
|
+
# fandoms and list of all available fandoms
|
16
26
|
class FandomRandomizer
|
17
27
|
include Singleton
|
18
28
|
require 'pathname'
|
19
29
|
require 'securerandom'
|
20
30
|
require_relative 'fandom_word_catalog'
|
21
31
|
|
22
|
-
attr_accessor :catalog
|
23
|
-
|
24
32
|
DATA_PATH = '../data/words.data'.freeze
|
33
|
+
private_constant :DATA_PATH
|
25
34
|
|
35
|
+
# Caches word catalog into memory for performance
|
26
36
|
def initialize
|
27
37
|
load_word_catalog
|
28
38
|
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
# Returns random word from any fandom in catalog. Fandom category can be specified.
|
41
|
+
#
|
42
|
+
# @param [String, Array] fandom_name_or_names Fandom category or array of categories
|
43
|
+
# @return [String] Random word
|
44
|
+
def random_word(fandom_name_or_names = random_fandom)
|
45
|
+
fandom_name = case fandom_name_or_names
|
46
|
+
when Array
|
47
|
+
validate_fandom_list fandom_name_or_names
|
48
|
+
random_fandom_name_from fandom_name_or_names
|
49
|
+
when String
|
50
|
+
fandom_name_or_names
|
51
|
+
else
|
52
|
+
raise ArgumentError, "Argument must be [Array, String] not #{fandom_name_or_names.class}"
|
53
|
+
end
|
36
54
|
|
37
|
-
|
38
|
-
category = @catalog.get_category fandom_name
|
39
|
-
category[SecureRandom.random_number category.size]
|
55
|
+
fetch_fandom fandom_name
|
40
56
|
end
|
41
57
|
|
58
|
+
# Returns the list of fandoms (categories)
|
42
59
|
def available_fandoms
|
43
60
|
@catalog.fandoms
|
44
61
|
end
|
45
62
|
|
63
|
+
private
|
64
|
+
|
65
|
+
def fetch_fandom(fandom_name)
|
66
|
+
validate_fandom fandom_name
|
67
|
+
category = @catalog.fetch_fandom fandom_name
|
68
|
+
category[SecureRandom.random_number category.size]
|
69
|
+
end
|
70
|
+
|
71
|
+
def random_fandom
|
72
|
+
random_fandom_name_from available_fandoms
|
73
|
+
end
|
74
|
+
|
75
|
+
def random_fandom_name_from(fandom_list)
|
76
|
+
fandom_list[SecureRandom.random_number fandom_list.size]
|
77
|
+
end
|
78
|
+
|
46
79
|
def load_word_catalog
|
47
80
|
file_path = Pathname(File.dirname(__FILE__)) + DATA_PATH
|
48
81
|
source = File.read(file_path, mode: 'rb')
|
49
82
|
# rubocop:disable Security/MarshalLoad
|
50
83
|
@catalog = Marshal.load(source) if @catalog.nil?
|
51
84
|
end
|
85
|
+
|
86
|
+
def validate_fandom(fandom_name)
|
87
|
+
return if available_fandoms.include? fandom_name
|
88
|
+
raise ArgumentError, "Invalid #{fandom_name}, Valid fandoms #{available_fandoms}"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Raises if fandom_list is using a fandom not in available fandoms
|
92
|
+
def validate_fandom_list(fandom_list)
|
93
|
+
return if (fandom_list & available_fandoms).size == fandom_list.size
|
94
|
+
raise ArgumentError, "Explicit List: #{fandom_list} \n Available Fandoms: #{available_fandoms}"
|
95
|
+
end
|
52
96
|
end
|
53
97
|
end
|
data/lib/fandom_word_catalog.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module FandomWord
|
2
|
-
# FandomWordCatalog
|
2
|
+
# FandomWordCatalog is a catalog holding all words in groups of fandoms.
|
3
3
|
class FandomWordCatalog
|
4
4
|
def initialize
|
5
5
|
@fandoms = {}
|
6
6
|
end
|
7
7
|
|
8
|
+
# Returns an array of words associated with the specified fandom. Initializes fandom in catalog if not present.
|
8
9
|
def fetch_fandom(fandom)
|
9
10
|
# grab the category if it exists, if not make it empty array
|
10
11
|
@fandoms.keys.include?(fandom) ? @fandoms[fandom] : @fandoms[fandom] = []
|
11
12
|
end
|
12
13
|
|
14
|
+
# Adds a word to a fandom
|
13
15
|
def add_word(new_word, categories)
|
14
16
|
categories.each do |category|
|
15
17
|
fandom = fetch_fandom(category)
|
@@ -17,6 +19,7 @@ module FandomWord
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
22
|
+
# Returns the list of fandoms (categories)
|
20
23
|
def fandoms
|
21
24
|
@fandoms.keys
|
22
25
|
end
|
data/lib/fandoms.rb
CHANGED
@@ -1,30 +1,67 @@
|
|
1
1
|
module FandomWord
|
2
|
+
# Available Fandoms. Categories to choose for your random word.
|
2
3
|
module Fandoms
|
4
|
+
# Available fandom category anime
|
3
5
|
ANIME = 'anime'.freeze
|
6
|
+
# Available fandom category bigo
|
4
7
|
BIGO = 'bigo'.freeze
|
8
|
+
# Available fandom category mech
|
5
9
|
MECH = 'mech'.freeze
|
10
|
+
# Available fandom category mecha
|
6
11
|
MECHA = 'mecha'.freeze
|
7
|
-
|
12
|
+
# Available fandom category neo-noir
|
8
13
|
NEO_NOIR = 'neo-noir'.freeze
|
14
|
+
# Available fandom category noir
|
15
|
+
NOIR = 'noir'.freeze
|
16
|
+
# Available fandom category scifi
|
9
17
|
SCIFI = 'scifi'.freeze
|
10
|
-
|
18
|
+
# Available fandom category martialarts
|
11
19
|
MARTIALARTS = 'martialarts'.freeze
|
20
|
+
# Available fandom category supernatural
|
21
|
+
SUPERNATURAL = 'supernatural'.freeze
|
22
|
+
# Available fandom category dbz
|
12
23
|
DBZ = 'dbz'.freeze
|
24
|
+
# Available fandom category dragonball
|
13
25
|
DRAGONBALL = 'dragonball'.freeze
|
14
|
-
|
26
|
+
# Available fandom category dragonballgt
|
15
27
|
DRAGONBALLGT = 'dragonballgt'.freeze
|
28
|
+
# Available fandom category dragonballsuper
|
16
29
|
DRAGONBALLSUPER = 'dragonballsuper'.freeze
|
30
|
+
# Available fandom category dragonballz
|
31
|
+
DRAGONBALLZ = 'dragonballz'.freeze
|
32
|
+
# Available fandom category ggundam
|
33
|
+
GGUNDAM = 'ggundam'.freeze
|
34
|
+
# Available fandom category gundam
|
17
35
|
GUNDAM = 'gundam'.freeze
|
36
|
+
# Available fandom category gundamwing
|
18
37
|
GUNDAMWING = 'gundamwing'.freeze
|
38
|
+
# Available fandom category mobilesuit
|
19
39
|
MOBILESUIT = 'mobilesuit'.freeze
|
40
|
+
# Available fandom category zetagundam
|
20
41
|
ZETAGUNDAM = 'zetagundam'.freeze
|
21
|
-
|
22
|
-
WESTERN = 'western'.freeze
|
42
|
+
# Available fandom category neo-western
|
23
43
|
NEO_WESTERN = 'neo-western'.freeze
|
44
|
+
# Available fandom category spacewestern
|
24
45
|
SPACEWESTERN = 'spacewestern'.freeze
|
46
|
+
# Available fandom category weirdwest
|
25
47
|
WEIRDWEST = 'weirdwest'.freeze
|
48
|
+
# Available fandom category western
|
49
|
+
WESTERN = 'western'.freeze
|
50
|
+
# Available fandom category rick_and_morty
|
51
|
+
RICK_AND_MORTY = 'rick_and_morty'.freeze
|
52
|
+
# Available fandom category games
|
53
|
+
GAMES = 'games'.freeze
|
54
|
+
# Available fandom category metal_gear_solid
|
55
|
+
METAL_GEAR_SOLID = 'metal_gear_solid'.freeze
|
56
|
+
# Available fandom category mgs
|
57
|
+
MGS = 'mgs'.freeze
|
58
|
+
# Available fandom category british
|
59
|
+
BRITISH = 'british'.freeze
|
60
|
+
# Available fandom category drwho
|
26
61
|
DRWHO = 'drwho'.freeze
|
62
|
+
# Available fandom category whovian
|
27
63
|
WHOVIAN = 'whovian'.freeze
|
28
|
-
|
64
|
+
# Available fandom category firefly
|
65
|
+
FIREFLY = 'firefly'.freeze
|
29
66
|
end
|
30
67
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fandom-word
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ravi Nath
|
@@ -9,22 +9,48 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-11-
|
12
|
+
date: 2017-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: A fandom word generator that returns random words from various fandoms.
|
15
15
|
email:
|
16
16
|
- majindm24@gmail.com
|
17
|
-
- manni@
|
17
|
+
- manni.reies@gmail.com
|
18
18
|
executables: []
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- ".gitattributes"
|
22
23
|
- ".gitignore"
|
24
|
+
- ".rspec"
|
23
25
|
- ".rubocop.yml"
|
26
|
+
- ".travis.yml"
|
27
|
+
- ".yardoc/checksums"
|
28
|
+
- ".yardoc/complete"
|
29
|
+
- ".yardoc/object_types"
|
30
|
+
- ".yardoc/objects/root.dat"
|
31
|
+
- ".yardoc/proxy_types"
|
24
32
|
- Gemfile
|
25
33
|
- README.md
|
26
34
|
- Rakefile
|
27
35
|
- data/words.data
|
36
|
+
- doc/FandomWord.html
|
37
|
+
- doc/FandomWord/FandomRandomizer.html
|
38
|
+
- doc/FandomWord/FandomWordCatalog.html
|
39
|
+
- doc/FandomWord/Fandoms.html
|
40
|
+
- doc/_index.html
|
41
|
+
- doc/class_list.html
|
42
|
+
- doc/css/common.css
|
43
|
+
- doc/css/full_list.css
|
44
|
+
- doc/css/style.css
|
45
|
+
- doc/file.README.html
|
46
|
+
- doc/file_list.html
|
47
|
+
- doc/frames.html
|
48
|
+
- doc/index.html
|
49
|
+
- doc/js/app.js
|
50
|
+
- doc/js/full_list.js
|
51
|
+
- doc/js/jquery.js
|
52
|
+
- doc/method_list.html
|
53
|
+
- doc/top-level-namespace.html
|
28
54
|
- fandom-word.gemspec
|
29
55
|
- lib/fandom-word.rb
|
30
56
|
- lib/fandom_word.rb
|