word_counter 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/bin/word_counter +8 -3
- data/lib/word_counter.rb +11 -10
- data/lib/word_counter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a0d420b2bc220bf3303c5b2a25939dd7a913a9
|
4
|
+
data.tar.gz: 820f8f29ff3a54921a730b3ef67eaee8ed8cb73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b0c8ac6c477814521d9e45067db7bf92c0122acefd1a40268edca6c4e66d0e9e3db44edc199b2f90666a4f47dc5fd4f7e442db990992b80244955878eac8798
|
7
|
+
data.tar.gz: bef591f767adb60f0c9e6188eaefafb9aab123ee6810bcafe506cb2fc4c2572c0fd0943857b88634fa76e1bf166bc3e7c3f3f915ffec59b1cfdd39b19ffe0203
|
data/README.md
CHANGED
@@ -56,10 +56,16 @@ Use the `-s` switch to also report which lines contained the counted word (can r
|
|
56
56
|
1: This domain is established to be used for illustrative examples in documents. You may use this
|
57
57
|
2: domain in examples without prior coordination or asking for permission.
|
58
58
|
|
59
|
+
## Options
|
60
|
+
|
61
|
+
-c Colorize output
|
62
|
+
-s Show sentences containing the words in question
|
63
|
+
|
59
64
|
## Roadmap
|
60
65
|
|
61
|
-
-
|
62
|
-
-
|
66
|
+
- Make color optional and not-default (-c switch)
|
67
|
+
- Ignore common words (a, for, it, the, of, etc.
|
68
|
+
- Ignore case
|
63
69
|
|
64
70
|
## Contributing
|
65
71
|
|
data/bin/word_counter
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'word_counter'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def get_switch name
|
6
|
+
i = ARGV.index(name) || -1
|
7
|
+
ARGV.delete_at i if i >= 0
|
8
|
+
end
|
9
|
+
|
10
|
+
show_sentences = get_switch '-s'
|
11
|
+
colorize = get_switch '-c'
|
12
|
+
wc = WordCounter.new ARGV[0], show_sentences, colorize
|
8
13
|
wc.report
|
data/lib/word_counter.rb
CHANGED
@@ -14,9 +14,10 @@ class WordCounter
|
|
14
14
|
#
|
15
15
|
# @param filename [String] The path and filename of the file to analyze
|
16
16
|
# @param show_sentences [Boolean] (default: false) If true, WordCounter will print out the sentences which contain the counted word in question
|
17
|
-
def initialize arg, show_sentences = false
|
17
|
+
def initialize arg, show_sentences = false, colorize = false
|
18
18
|
raise ArgumentError, "Please supply a URL or file path." unless arg
|
19
|
-
@show_sentences =
|
19
|
+
@show_sentences = show_sentences
|
20
|
+
@colorize = colorize
|
20
21
|
|
21
22
|
begin
|
22
23
|
# try to open it as a file
|
@@ -35,30 +36,30 @@ class WordCounter
|
|
35
36
|
end
|
36
37
|
|
37
38
|
|
38
|
-
def colorize str
|
39
|
-
str.to_s.
|
39
|
+
def colorize str, options
|
40
|
+
@colorize ? str.to_s.colorize(options) : str
|
40
41
|
end
|
41
42
|
|
42
43
|
|
43
44
|
##
|
44
45
|
# Prints a report to stdout
|
45
46
|
def report
|
46
|
-
hashified_words_with_sorted_lines = @hashified_words.each do |word, data|
|
47
|
-
|
48
|
-
end
|
47
|
+
# hashified_words_with_sorted_lines = @hashified_words.each do |word, data|
|
48
|
+
# data[:lines].sort
|
49
|
+
# end
|
49
50
|
|
50
|
-
sorted_hash =
|
51
|
+
sorted_hash = @hashified_words.sort_by { |word, data|
|
51
52
|
[-data[:count], word]
|
52
53
|
}
|
53
54
|
|
54
55
|
puts 'Results:'
|
55
56
|
sorted_hash.each do |word, data|
|
56
|
-
puts
|
57
|
+
puts(colorize "#{data[:count]} #{word}", color: :green, mode: :bold)
|
57
58
|
|
58
59
|
i = 0
|
59
60
|
lines = data[:lines].map { |l|
|
60
61
|
i += 1
|
61
|
-
"#{i
|
62
|
+
"#{colorize i, color: :red}: #{l}"
|
62
63
|
}.join("\n ")
|
63
64
|
|
64
65
|
puts " #{lines}" if show_sentences?
|
data/lib/word_counter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: word_counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- trevor bortins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|