madlibber 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/madlibber/version.rb +1 -1
- data/lib/madlibber.rb +32 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e2d914e3522e7ce8d1709efe8eb2d1233ca50d
|
4
|
+
data.tar.gz: 1ebea58664957f3681f4ab5a2e8bffd4032016af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32dea54037f33a16ceabfe472270aa94f4977a9b3c45d7f7ffa06ba0ead858186bbe93a93ed87ae0e1d784fcc40851ef8adb4647d0d8d97d74e31b7e5105d5a2
|
7
|
+
data.tar.gz: 4dd53337a64c130dcc2318680f1ced56b05a8f31ba8a408adb2c14f613e7006f4c019ebeff5106ad0337ae7a680aab266a753dda908c34df8b0239dd5937c8a2
|
data/lib/madlibber/version.rb
CHANGED
data/lib/madlibber.rb
CHANGED
@@ -6,7 +6,7 @@ module MadLibber
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
OPTIONS = {
|
9
|
-
num_of_blanks: 10
|
9
|
+
num_of_blanks: 10,
|
10
10
|
}
|
11
11
|
|
12
12
|
TAGS = {
|
@@ -21,6 +21,18 @@ module MadLibber
|
|
21
21
|
"UH" => "<interjection>"
|
22
22
|
}
|
23
23
|
|
24
|
+
TAGS_HTML = {
|
25
|
+
"NN" => "<input type='text' placeholder='noun'>",
|
26
|
+
"NNS" => "<input type='text' placeholder='plural_noun'>",
|
27
|
+
"NNP" => "<input type='text' placeholder='proper_noun'>",
|
28
|
+
"VB" => "<input type='text' placeholder='verb'>",
|
29
|
+
"VBD" => "<input type='text' placeholder='verb_past_tense'>",
|
30
|
+
"VBG" => "<input type='text' placeholder='verb_ending_with_ing'>",
|
31
|
+
"JJ" => "<input type='text' placeholder='adjective'>",
|
32
|
+
"RB" => "<input type='text' placeholder='adverb'>",
|
33
|
+
"UH" => "<input type='text' placeholder='interjection'>"
|
34
|
+
}
|
35
|
+
|
24
36
|
def libberfy text, options = OPTIONS
|
25
37
|
defaults = OPTIONS
|
26
38
|
defaults.merge! options
|
@@ -31,9 +43,25 @@ module MadLibber
|
|
31
43
|
tag_word_pairs = tagged_text.split.map { |tagged_word| create_tag_word_pairs tagged_word }
|
32
44
|
fillable_indices = find_fillable_indices(tag_word_pairs).shuffle.take defaults[:num_of_blanks]
|
33
45
|
|
34
|
-
tag_word_pairs
|
35
|
-
|
36
|
-
|
46
|
+
generate_output tag_word_pairs, fillable_indices, defaults[:html_form]
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_output tag_word_pairs, fillable_indices, html_form_flag
|
50
|
+
output_array = tag_word_pairs.map.with_index do |tw_pair, index|
|
51
|
+
if fillable_indices.include? index
|
52
|
+
html_form_flag ? TAGS_HTML[ tw_pair[:tag] ] : TAGS[ tw_pair[:tag] ]
|
53
|
+
else
|
54
|
+
tw_pair[:word]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if html_form_flag
|
59
|
+
output_array.unshift "<form id='madlib-form'>"
|
60
|
+
output_array << "<input type='submit'>"
|
61
|
+
output_array << "</form>"
|
62
|
+
end
|
63
|
+
|
64
|
+
output_array.join(" ").gsub " '", "'"
|
37
65
|
end
|
38
66
|
|
39
67
|
def create_tag_word_pairs word
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madlibber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Samskies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|