madlibber 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: f85ea0343e4de0d7c9ded43e4035a76b8c968f7e
4
- data.tar.gz: c8dfd9303c595a01d219591107780bd80cf1aef4
3
+ metadata.gz: 84e2d914e3522e7ce8d1709efe8eb2d1233ca50d
4
+ data.tar.gz: 1ebea58664957f3681f4ab5a2e8bffd4032016af
5
5
  SHA512:
6
- metadata.gz: 56504558613c0c7485329667cbceb5770e2ec9c791962ac2834d1c82c35d83112887b99846aa70579abe72b977a89e264e7fd0480b222e5a683cf23174290d96
7
- data.tar.gz: 65754479411c6c5491c7e97a905757a1a1fbc216fb9f1468e3467c7a6d9f0e77bbb2fecd9811243118cd185c371367000294d3ce99d86d9138cae81d9e81a764
6
+ metadata.gz: 32dea54037f33a16ceabfe472270aa94f4977a9b3c45d7f7ffa06ba0ead858186bbe93a93ed87ae0e1d784fcc40851ef8adb4647d0d8d97d74e31b7e5105d5a2
7
+ data.tar.gz: 4dd53337a64c130dcc2318680f1ced56b05a8f31ba8a408adb2c14f613e7006f4c019ebeff5106ad0337ae7a680aab266a753dda908c34df8b0239dd5937c8a2
@@ -1,3 +1,3 @@
1
1
  module Madlibber
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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.map.with_index do |tw_pair, index|
35
- (fillable_indices.include? index) ? TAGS[ tw_pair[:tag] ] : tw_pair[:word]
36
- end.join(" ").gsub " '", "'"
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
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-23 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler