words_counted 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +67 -49
- data/lib/words_counted/counter.rb +2 -0
- data/lib/words_counted/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74d7a0ee0210b034e5babbe9f90f11cd0c5db8b
|
4
|
+
data.tar.gz: f1852e2f1f728b7a22c519d43e670078edc61509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8edcbac512ac3edaf9dfc1a28a66e55e34e7ca33c9db57688c8c5658c0f5b514c1585316d7657389ce3ed40c1b91c0dd58aefca24c2c0b1d7ab91736cb30f80
|
7
|
+
data.tar.gz: 5019a1db7d42ef06068e24e666efe90f54bc7ac3821bbb9b2232506644712fa985592dfcdcf6a3310945ec940002a6b037665685aebcb645052262accb2ccd86
|
data/README.md
CHANGED
@@ -52,21 +52,23 @@ Returns a hash map of words and their number of occurrences. Uppercase and lower
|
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
counter.word_occurrences
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
55
|
+
#
|
56
|
+
# {
|
57
|
+
# "we" => 1,
|
58
|
+
# "are" => 2,
|
59
|
+
# "all" => 1,
|
60
|
+
# "in" => 1,
|
61
|
+
# "the" => 2,
|
62
|
+
# "gutter" => 1,
|
63
|
+
# "but" => 1,
|
64
|
+
# "some" => 1,
|
65
|
+
# "of" => 1,
|
66
|
+
# "us" => 1,
|
67
|
+
# "looking" => 1,
|
68
|
+
# "at" => 1,
|
69
|
+
# "stars" => 1
|
70
|
+
# }
|
71
|
+
#
|
70
72
|
```
|
71
73
|
|
72
74
|
#### `.most_occurring_words`
|
@@ -75,11 +77,12 @@ Returns a two dimensional array of the most occurring word and its number of occ
|
|
75
77
|
|
76
78
|
```ruby
|
77
79
|
counter.most_occurring_words
|
78
|
-
|
79
|
-
[
|
80
|
-
["are", 2],
|
81
|
-
["the", 2]
|
82
|
-
]
|
80
|
+
#
|
81
|
+
# [
|
82
|
+
# ["are", 2],
|
83
|
+
# ["the", 2]
|
84
|
+
# ]
|
85
|
+
#
|
83
86
|
```
|
84
87
|
|
85
88
|
#### `.word_lengths`
|
@@ -88,21 +91,23 @@ Returns a hash of words and their lengths.
|
|
88
91
|
|
89
92
|
```ruby
|
90
93
|
counter.word_lengths
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
94
|
+
#
|
95
|
+
# {
|
96
|
+
# "We" => 2,
|
97
|
+
# "are" => 3,
|
98
|
+
# "all" => 3,
|
99
|
+
# "in" => 2,
|
100
|
+
# "the" => 3,
|
101
|
+
# "gutter" => 6,
|
102
|
+
# "but" => 3,
|
103
|
+
# "some" => 4,
|
104
|
+
# "of" => 2,
|
105
|
+
# "us" => 2,
|
106
|
+
# "looking" => 7,
|
107
|
+
# "at" => 2,
|
108
|
+
# "stars" => 5
|
109
|
+
# }
|
110
|
+
#
|
106
111
|
```
|
107
112
|
|
108
113
|
#### `.longest_word`
|
@@ -111,9 +116,20 @@ Returns a two dimensional array of the longest word and its length. In case ther
|
|
111
116
|
|
112
117
|
```ruby
|
113
118
|
counter.longest_words
|
114
|
-
|
115
|
-
|
116
|
-
]
|
119
|
+
#
|
120
|
+
# [
|
121
|
+
# ["looking", 7]
|
122
|
+
# ]
|
123
|
+
#
|
124
|
+
```
|
125
|
+
|
126
|
+
#### `.words`
|
127
|
+
|
128
|
+
Returns an array of words resulting from the string passed into the initialize method.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
counter.words
|
132
|
+
#=> ["We", "are", "all", "in", "the", "gutter", "but", "some", "of", "us", "are", "looking", "at", "the", "stars"]
|
117
133
|
```
|
118
134
|
|
119
135
|
## Filtering
|
@@ -134,17 +150,19 @@ counter = WordsCounted::Counter.new("How do you do?-you are well, I see.")
|
|
134
150
|
#<WordsCounted::Counter:0x007fd494252518 @words=["How", "do", "you", "do", "-you", "are", "well", "I", "see"]>
|
135
151
|
|
136
152
|
counter.word_occurrences
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
153
|
+
#
|
154
|
+
# {
|
155
|
+
# "how" => 1,
|
156
|
+
# "do" => 2,
|
157
|
+
# "you" => 1,
|
158
|
+
# "-you" => 1, # WTF, mate!
|
159
|
+
# "are" => 1,
|
160
|
+
# "very" => 1,
|
161
|
+
# "well" => 1,
|
162
|
+
# "i" => 1,
|
163
|
+
# "see" => 1
|
164
|
+
# }
|
165
|
+
#
|
148
166
|
```
|
149
167
|
|
150
168
|
In this example, `-you` and `you` are counted as separate words. Writers should use the correct dash element, but this is not always the case.
|
@@ -68,6 +68,8 @@ module WordsCounted
|
|
68
68
|
#
|
69
69
|
# {http://codereview.stackexchange.com/a/47515/1563 See here}.
|
70
70
|
#
|
71
|
+
# @param entries [Hash] a hash of entries to analyse
|
72
|
+
#
|
71
73
|
def highest_ranking(entries)
|
72
74
|
entries.group_by { |word, occurrence| occurrence }.sort.last.last
|
73
75
|
end
|