wordsoup 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fbb14045261c2ce7618e9b1a0c5e30118922aed
4
+ data.tar.gz: 758797db870ed696c6a7cac56a0bbb5866fca97e
5
+ SHA512:
6
+ metadata.gz: ab3328c0073de488b7a7377c75a8ba9b6678a748f7aba98571c2bd5aa517b28d6da305b37ed3ac246e75921f7e702d10531563473180ca07e67127bf5d84cc47
7
+ data.tar.gz: 9f7d4ebdc8d51d6b56b2b2b3b8135406fc7f83d7419ff20963b6d12ae382b5022544530eba2d639c375295ce9ba0a5052d22f101cbc6bf1d8a959771e7f241b1
data/.byebug_history ADDED
@@ -0,0 +1,7 @@
1
+ c
2
+ exit
3
+ word
4
+ exit
5
+ sentence[i]
6
+ word
7
+ sentence
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
+ .byebug_history
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wordsoup.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Wordsoup
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/wordsoup`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'wordsoup'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install wordsoup
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wordsoup.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/author.rb ADDED
@@ -0,0 +1,110 @@
1
+ require 'byebug'
2
+ class Author
3
+
4
+ attr_accessor :sentences, :word_hash, :first_words, :last_words
5
+
6
+ def initialize(file)
7
+ @sentences = make_sentence_array(file)
8
+ @word_hash = Hash.new { |h, k| h[k] = [] }
9
+ @first_words = []
10
+ @last_words = []
11
+ make_word_hash
12
+ end
13
+
14
+ def make_sentence_array(file)
15
+ text = ""
16
+ File.open(file).each do |line|
17
+ text << line
18
+ end
19
+ text = text.gsub(/\n/, " ")
20
+ text = text.gsub(/"/, "")
21
+ sentences = text.split(" ")
22
+ end
23
+
24
+
25
+ def make_word_hash()
26
+ @sentences.each do |sentence|
27
+ sentence_array = sentence.split(" ")
28
+ sentence_array.each_with_index do |word, i|
29
+ @first_words << word if i == 0
30
+ @last_words << word if i == sentence_array.length - 1
31
+ unless i == sentence_array.length - 1
32
+ @word_hash[word] << sentence_array[i+1]
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def sentence
39
+ sentence = [@first_words.sample.capitalize]
40
+ word = ""
41
+ until (sentence.length == 30)
42
+ word = @word_hash[sentence.last].sample
43
+ break if word.nil?
44
+ word = fix_word(word)
45
+ sentence << word
46
+ break if ["!","?","."].include?(word[word.length-1])
47
+ end
48
+ sentence = sentence.join(" ")
49
+ sentence[sentence.length-1] = "" if [",", ":", ";"].include?(sentence[sentence.length-1])
50
+ unless ["!","?","."].include?(sentence[sentence.length-1])
51
+ sentence << "?"
52
+ end
53
+ sentence
54
+ end
55
+
56
+ def paragraph
57
+ paragraph = ""
58
+ until paragraph.length > 250
59
+ paragraph << " "
60
+ paragraph << self.sentence
61
+ end
62
+ paragraph
63
+ end
64
+
65
+ def fix_word(word)
66
+ word = word.downcase
67
+ capitalized_words = ["i'll", "i", "god", "i."]
68
+ if capitalized_words.include?(word)
69
+ word = word.capitalize
70
+ end
71
+ word
72
+ end
73
+
74
+ end
75
+
76
+ class Shakespeare < Author
77
+
78
+ def initialize(file = "hamlet.txt")
79
+ super(file)
80
+ end
81
+
82
+ end
83
+
84
+ class Hemingway < Author
85
+
86
+ def initialize(file = "omats.txt")
87
+ super(file)
88
+ end
89
+
90
+ end
91
+
92
+ class Hemingway < Author
93
+
94
+ def initialize(file = "omats.txt")
95
+ super(file)
96
+ end
97
+
98
+ end
99
+ class Bible < Author
100
+
101
+ def initialize(file = "bible.txt")
102
+ super(file)
103
+ end
104
+
105
+ end
106
+
107
+
108
+
109
+ $Shakespeare = Author.new('hamlet.txt')
110
+ $Hemingway = Author.new('omats.txt')
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wordsoup"
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