words_counted 0.1.4 → 0.1.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +10 -9
- data/lib/words_counted/counter.rb +3 -2
- data/lib/words_counted/version.rb +2 -1
- data/lib/words_counted.rb +1 -0
- metadata +16 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cba04e2004b13b0ee7b99e46cdf6549f6aebe2f6
|
|
4
|
+
data.tar.gz: 885d494f7f2b2af40f59ed08aaca1db7ec89a54b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2009cd4b401da2b43047699a073a3f541654384d831d73c0d436016eb88325e29c179a59961c6d1d8d48a865f34a2da78e014a28a5e0cf4ccf714cafa7a6bb5
|
|
7
|
+
data.tar.gz: f46e0031db714c0985ef4b2dee5d1f294c9ab0bdb629157110af0b26b76280bfe440207b4f6920156681cc91ded0246e3e66b6dcf26717208cc73ebbe4e86821
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
## Version 0.1.5
|
|
2
|
+
|
|
3
|
+
1. Removed `to_f` from the dividend in `average_chars_per_word` and `word_densities`. The divisor is a float, and dividing by a float returns a float.
|
|
4
|
+
2. Added `# -*- encoding : utf-8 -*-` to all files. See [pull request][1].
|
|
5
|
+
3. Added this changelog.
|
|
6
|
+
|
|
7
|
+
[1]: https://github.com/abitdodgy/words_counted/pull/12
|
data/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# WordsCounted
|
|
2
2
|
|
|
3
|
-
WordsCounted is a highly customisable Ruby
|
|
3
|
+
WordsCounted is a highly customisable Ruby text analyser. Consult the features for more information.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<a href="http://badge.fury.io/rb/words_counted">
|
|
6
|
+
<img src="https://badge.fury.io/rb/words_counted@2x.png" alt="Gem Version" height="18">
|
|
7
|
+
</a>
|
|
8
8
|
|
|
9
9
|
### Demo
|
|
10
10
|
|
|
@@ -22,13 +22,14 @@ Visit [the gem's website][4] for a demo.
|
|
|
22
22
|
* A hash map of words and their lengths
|
|
23
23
|
* The longest word(s) and its length
|
|
24
24
|
* The most occurring word(s) and its number of occurrences.
|
|
25
|
+
* Count invividual strings for occurrences.
|
|
25
26
|
* A flexible way to exclude words (or anything) from the count. You can pass a **string**, a **regexp**, an **array**, or a **lambda**.
|
|
26
27
|
* Customisable criteria. Pass your own regexp rules to split strings if you prefer. The default regexp has two features:
|
|
27
28
|
* Filters special characters but respects hyphens and apostrophes.
|
|
28
29
|
* Plays nicely with diacritics (UTF and unicode characters): "São Paulo" is treated as `["São", "Paulo"]` and not `["S", "", "o", "Paulo"]`.
|
|
29
|
-
* Pass in a file path or a url instead of a string.
|
|
30
|
+
* Opens and reads files. Pass in a file path or a url instead of a string.
|
|
30
31
|
|
|
31
|
-
See usage instructions for details
|
|
32
|
+
See usage instructions for more details.
|
|
32
33
|
|
|
33
34
|
## Installation
|
|
34
35
|
|
|
@@ -44,7 +45,7 @@ Or install it yourself as:
|
|
|
44
45
|
|
|
45
46
|
$ gem install words_counted
|
|
46
47
|
|
|
47
|
-
##
|
|
48
|
+
## Usage
|
|
48
49
|
|
|
49
50
|
Pass in a string or a file path, and an optional filter and/or regexp.
|
|
50
51
|
|
|
@@ -71,12 +72,12 @@ counter = WordsCounted.count("Hello Beirut!")
|
|
|
71
72
|
|
|
72
73
|
Accepts two options: `exclude` and `regexp`. See [Excluding words from the analyser][5] and [Passing in a custom regexp][6] respectively.
|
|
73
74
|
|
|
74
|
-
#### from_file(path, options = {})
|
|
75
|
+
#### `from_file(path, options = {})`
|
|
75
76
|
|
|
76
77
|
Initializes an analyser object from a file path.
|
|
77
78
|
|
|
78
79
|
```ruby
|
|
79
|
-
counter = WordsCounted.count("
|
|
80
|
+
counter = WordsCounted.count("hello_beirut.txt")
|
|
80
81
|
````
|
|
81
82
|
|
|
82
83
|
Accepts the same options as `count()`.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
1
2
|
module WordsCounted
|
|
2
3
|
class Counter
|
|
3
4
|
attr_reader :words, :word_occurrences, :word_lengths, :char_count
|
|
@@ -28,7 +29,7 @@ module WordsCounted
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def average_chars_per_word(precision = 2)
|
|
31
|
-
(char_count
|
|
32
|
+
(char_count / word_count.to_f).round(precision)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def most_occurring_words
|
|
@@ -41,7 +42,7 @@ module WordsCounted
|
|
|
41
42
|
|
|
42
43
|
def word_density(precision = 2)
|
|
43
44
|
word_densities = word_occurrences.each_with_object({}) do |(word, occ), hash|
|
|
44
|
-
hash[word] = (occ
|
|
45
|
+
hash[word] = (occ / word_count.to_f * 100).round(precision)
|
|
45
46
|
end
|
|
46
47
|
sort_by_descending_value word_densities
|
|
47
48
|
end
|
data/lib/words_counted.rb
CHANGED
metadata
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: words_counted
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mohamad El-Husseini
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.3'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: pry
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- -
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
69
|
description: A Ruby word counter and string analyser with helpful utility methods.
|
|
@@ -73,9 +73,10 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
-
- .gitignore
|
|
77
|
-
- .rspec
|
|
78
|
-
- .yardopts
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".yardopts"
|
|
79
|
+
- CHANGELOG.md
|
|
79
80
|
- Gemfile
|
|
80
81
|
- LICENSE.txt
|
|
81
82
|
- README.md
|
|
@@ -97,12 +98,12 @@ require_paths:
|
|
|
97
98
|
- lib
|
|
98
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
100
|
requirements:
|
|
100
|
-
- -
|
|
101
|
+
- - ">="
|
|
101
102
|
- !ruby/object:Gem::Version
|
|
102
103
|
version: '0'
|
|
103
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
requirements:
|
|
105
|
-
- -
|
|
106
|
+
- - ">="
|
|
106
107
|
- !ruby/object:Gem::Version
|
|
107
108
|
version: '0'
|
|
108
109
|
requirements: []
|