text_analyzr 0.0.5.Alpha

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: d7d97a03a984bff2adeca8dd8c7428f5b7224d44
4
+ data.tar.gz: 38a68e41df43edb6d5e15721daad3dbbeff75a0d
5
+ SHA512:
6
+ metadata.gz: b879e6afb386d4a2dd6bf25c90b5131eb36f13bfde7238da434733ade4cc1c061d6b4e7427ea0e7cc830e798bf266f2a10b4ad561b3f41c3b0898f8753536008
7
+ data.tar.gz: a78041af899e5fa42b4c2a50e1d526c82629b8df495cac37d7bc053405e2ce7242fbfef4a9e3b6c29f06d54d650c788f18cec8eb0f5c93e7d75f984a7aa5c786
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in text_analiyzr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Wilkin Novo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # TextAnalyzr
2
+
3
+ TextAnalyzr: Analizes files on the fly with some nice output info
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'text_analyzr', '~> 0.0.3.Alpha'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install text_analyzr --pre
18
+
19
+ ## Usage
20
+
21
+ Instantiate a new object passing in your file as an argument:
22
+ ```ruby
23
+ file = TextAnalyzr::Analysis.new("../LICENSE.txt")
24
+ ```
25
+ then > call analyze on your object:
26
+ ```ruby
27
+ puts file.analyze
28
+ ```
29
+ Check out the source code for all methods you can call.
30
+
31
+ ## Todo
32
+ * Improved methods
33
+ * Better documentation
34
+ * more...
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module TextAnalyzr
2
+ VERSION = "0.0.5.Alpha"
3
+ end
@@ -0,0 +1,85 @@
1
+ require "text_analyzr/version"
2
+
3
+ module TextAnalyzr
4
+
5
+ class Analysis
6
+
7
+ def initialize(file)
8
+ @file = file
9
+ end
10
+
11
+ def actual
12
+ File.readlines(@file)
13
+ end
14
+
15
+ def line_count
16
+ actual.size.to_s
17
+ end
18
+ # just reference
19
+ def array_joint
20
+ actual.join
21
+ end
22
+
23
+ # counts the characters
24
+ def character_count
25
+ array_joint.length.to_s
26
+ end
27
+
28
+ def character_count_nospaces
29
+ array_joint.gsub(/\s+/, '').length
30
+ end
31
+
32
+ # count the words, sentences, and paragraphs
33
+ def word_count
34
+ actual.to_s.split.length
35
+ end
36
+
37
+ def sentence_count
38
+ actual.to_s.split(/\.|\?|!/).length
39
+ end
40
+
41
+ def paragraph_count
42
+ actual.to_s.split(/\n\n/).length
43
+ end
44
+
45
+ # make list of words in the text that aren't stop words,
46
+ # count them, and work out the percentage of non-stop words
47
+ # against all words
48
+
49
+ def all_words
50
+ actual.to_s.scan(/\w+/)
51
+ end
52
+
53
+ def good_words
54
+ stopwords = %w{the a by on for are with just but and to my I has some in}
55
+ all_words.select{ |word| !stopwords.include?(word)}
56
+ end
57
+
58
+ def good_percentage
59
+ ((good_words.length.to_f / all_words.length.to_f) * 100).to_i
60
+ end
61
+
62
+ def sentences
63
+ actual.to_s.gsub(/\s+/, ' ').strip.split(/\.|\?|!/)
64
+ end
65
+
66
+ def sentences_sorted
67
+ sentences.sort_by{ |sentence| sentence.length }
68
+ end
69
+
70
+ def ideal_sentences
71
+ one_third = sentences_sorted.length / 3
72
+ sentences_sorted.slice(one_third, one_third + 1)
73
+ end
74
+
75
+ # a summary of the file
76
+ def summary
77
+ "Summary:\n\n" + ideal_sentences.join(". ")+ "\n" "-- End of analysis --"
78
+ end
79
+
80
+ # executes all methods
81
+ def analyze
82
+ "Analysis:" + "\n\n" + "#{line_count} lines " + "\n" + "#{character_count} characters" + "\n" + "#{character_count_nospaces} characters (excluding spaces)" + "\n" + "#{word_count} words" + "\n" + "#{sentence_count} sentences" + "\n" + "#{paragraph_count} paragraphs" + "\n" + "#{sentence_count / paragraph_count} sentence (s) per paragraphs (average)" + "\n" + "#{word_count / sentence_count} words per sentence (average)" + "\n" + "#{good_percentage} % of words are non-fluff words" + "\n\n" + summary
83
+ end
84
+ end
85
+ end
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'text_analyzr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "text_analyzr"
8
+ spec.version = TextAnalyzr::VERSION
9
+ spec.authors = ["Wilkin Novo"]
10
+ spec.email = ["novos100@gmail.com"]
11
+ spec.description = %q{TextAnalyzr: Analizes files on the fly with some nice output info about the file}
12
+ spec.summary = %q{Simple Ruby text file analyzer}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: text_analyzr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5.Alpha
5
+ platform: ruby
6
+ authors:
7
+ - Wilkin Novo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'TextAnalyzr: Analizes files on the fly with some nice output info about
42
+ the file'
43
+ email:
44
+ - novos100@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/text_analyzr.rb
54
+ - lib/text_analyzr/version.rb
55
+ - text_analyzr-0.0.1.Alpha.gem
56
+ - text_analyzr-0.0.2.Alpha.gem
57
+ - text_analyzr.gemspec
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>'
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.1
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Simple Ruby text file analyzer
82
+ test_files: []