wc 0.30.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/VERSION +1 -1
- data/bin/wc +5 -1
- data/lib/wc.rb +9 -3
- data/wc.gemspec +3 -3
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -12,6 +12,9 @@ wc gem is a very simple word counter. It takes a file in input and prints the wo
|
|
12
12
|
$ bin/wc --json filename
|
13
13
|
The same as the example above, except for the results that are printed in json notation.
|
14
14
|
|
15
|
+
$bin/wc -w x filename
|
16
|
+
It prints out only the first x words that appear with highest rate in filename
|
17
|
+
|
15
18
|
== Note on Patches/Pull Requests
|
16
19
|
|
17
20
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.40.0
|
data/bin/wc
CHANGED
@@ -6,12 +6,14 @@ require 'json'
|
|
6
6
|
|
7
7
|
opts = GetoptLong.new(
|
8
8
|
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
9
|
+
[ '--words', '-w', GetoptLong::REQUIRED_ARGUMENT],
|
9
10
|
[ '--version', '-v', GetoptLong::NO_ARGUMENT ],
|
10
11
|
[ '--json', '-j', GetoptLong::NO_ARGUMENT ],
|
11
12
|
[ '--xml', '-x', GetoptLong::NO_ARGUMENT ]
|
12
13
|
)
|
13
14
|
|
14
15
|
output = 'text'
|
16
|
+
words = -1
|
15
17
|
|
16
18
|
begin
|
17
19
|
opts.each do |opt, arg|
|
@@ -25,6 +27,8 @@ opts.each do |opt, arg|
|
|
25
27
|
exit 0
|
26
28
|
when '--json'
|
27
29
|
output = 'json'
|
30
|
+
when '--words'
|
31
|
+
words = arg.to_i
|
28
32
|
end
|
29
33
|
end
|
30
34
|
rescue
|
@@ -37,7 +41,7 @@ if ARGV.length != 1
|
|
37
41
|
exit 0
|
38
42
|
end
|
39
43
|
|
40
|
-
w = Wc.new(ARGV[0])
|
44
|
+
w = Wc.new(ARGV[0], words)
|
41
45
|
|
42
46
|
if output == 'text'
|
43
47
|
w.to_text
|
data/lib/wc.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
class Wc
|
2
|
-
attr_reader :filename, :occurrences
|
2
|
+
attr_reader :filename, :occurrences, :words
|
3
3
|
|
4
|
-
def initialize(filename)
|
4
|
+
def initialize(filename, words)
|
5
5
|
@filename = filename
|
6
6
|
@occurrences = read
|
7
7
|
@sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
|
8
|
-
|
8
|
+
@words = words
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_text
|
12
|
+
if @words == -1
|
12
13
|
@sorted.each { |elem|
|
13
14
|
puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
|
14
15
|
}
|
16
|
+
else
|
17
|
+
@sorted[0..@words-1].each { |elem|
|
18
|
+
puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
|
19
|
+
}
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def to_json
|
data/wc.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wc}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.40.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paolo Perego"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-30}
|
13
13
|
s.default_executable = %q{wc}
|
14
14
|
s.description = %q{your ruby word counter experience}
|
15
15
|
s.email = %q{thesp0nge@gmail.com}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 191
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 40
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.40.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paolo Perego
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-30 00:00:00 +02:00
|
19
19
|
default_executable: wc
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|