naknower 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/naknower.rb +49 -0
  3. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65298cb5c74b9436182c2f2f2169719a079e0324
4
+ data.tar.gz: c7a0ed5be6f6038a38762e88c1243353ce0b1032
5
+ SHA512:
6
+ metadata.gz: 417fde4f7641ae1a7657145d889ba040b8cead5d986729b0524479c76808c24725ab71ea6538cfad75b8e6e48deb7db4c41d82179fa73480ea248f873cfaf62e
7
+ data.tar.gz: cfce37feb4b5194a25a765c70fc1192c539a7aa9601663060f0207e0830a3d38a139d1410559e662e933033b1529cc3a63e39035e4232c7b7ba53c60f145225d
data/lib/naknower.rb ADDED
@@ -0,0 +1,49 @@
1
+ class Novel
2
+ attr_accessor :novel
3
+ def initialize input
4
+ @novel = ""
5
+ if input.kind_of?(File)
6
+ while line = input.gets
7
+ @novel += line + " "
8
+ end
9
+ elsif input.kind_of?(String)
10
+ @novel = input
11
+ else
12
+ puts "Please format your novel as either a file or a string. Thank you."
13
+ end
14
+ @list_format = @novel.split(" ")
15
+ @clean_text = @novel.gsub(/[.,?!()]/, "").downcase
16
+ @clean_list = @clean_text.split(" ")
17
+ end
18
+
19
+ def word_count
20
+ @list_format.size
21
+ end
22
+
23
+ def word_find word
24
+ result = 0
25
+ @clean_list.each do |element|
26
+ if word.downcase == element.downcase
27
+ result += 1
28
+ end
29
+ end
30
+ result
31
+ end
32
+
33
+ def word_frequency
34
+ dict = Hash.new(0)
35
+ result = []
36
+ @clean_list.each do |word|
37
+ dict[word] += 1
38
+ end
39
+ dict
40
+ end
41
+
42
+ def most_common_words
43
+ dict = word_frequency
44
+ dict.each do |key, value|
45
+ result.push(key) if value == dict.values.max
46
+ end
47
+ result
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: naknower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Whitehead
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "In this initial build, several functions are available on the Novel
14
+ object:\n \t\t\t\t\tword_count, which is self-explanatory\n \t\t\t\t\tword_frequency,
15
+ which returns a hash containing key value pairs of the 'word => number_of_times_that_word_appears_in_the_text'
16
+ variety\n \t\t\t\t\tword_find, which takes a string as an argument and returns
17
+ the number of times the string appears in text.\n \t\t\t\t\tmost_common_words,
18
+ which returns each of the words that is the most common or tied for most common.\n
19
+ \ \t\t\t\t\tAll functions are case-insensitive and ignore punctuation."
20
+ email: rob.whitehead@gmail.com
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - lib/naknower.rb
26
+ homepage: https://rubygems.org/gems/naknower
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Text Analysis gem intended for novel-length texts.
49
+ test_files: []