wc 0.92.0 → 0.93.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +3 -0
  2. data/VERSION +1 -1
  3. data/bin/wc +14 -3
  4. data/lib/wc.rb +9 -2
  5. data/wc.gemspec +2 -2
  6. metadata +4 -4
data/README.rdoc CHANGED
@@ -18,6 +18,9 @@ wc gem is a very simple word counter. It takes a file in input and prints the wo
18
18
  $bin/wc --cloud filename
19
19
  It prints out the result using definition list HTML tag. This can be used to generate tag clouds
20
20
 
21
+ $bin/wc -H filename
22
+ It prints out the result excluding some very common English idioms such as ('and', 'of', 'the', ...)
23
+
21
24
  == Note on Patches/Pull Requests
22
25
 
23
26
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.92.0
1
+ 0.93.0
data/bin/wc CHANGED
@@ -10,12 +10,13 @@ opts = GetoptLong.new(
10
10
  [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
11
11
  [ '--json', '-j', GetoptLong::NO_ARGUMENT ],
12
12
  [ '--xml', '-x', GetoptLong::NO_ARGUMENT ],
13
- [ '--cloud', '-c', GetoptLong::NO_ARGUMENT]
13
+ [ '--cloud', '-c', GetoptLong::NO_ARGUMENT],
14
+ [ '--hide-commons', '-H', GetoptLong::NO_ARGUMENT]
14
15
  )
15
16
 
16
17
  output = 'text'
17
18
  words = -1
18
-
19
+ hide_commons = 0
19
20
 
20
21
  begin
21
22
  opts.each do |opt, arg|
@@ -33,6 +34,8 @@ opts.each do |opt, arg|
33
34
  words = arg.to_i
34
35
  when '--cloud'
35
36
  output = 'cloud'
37
+ when '--hide-commons'
38
+ hide_commons = 1
36
39
  end
37
40
  end
38
41
  rescue
@@ -45,7 +48,15 @@ if ARGV.length != 1
45
48
  exit 0
46
49
  end
47
50
 
48
- w = Wc.new(ARGV[0], words)
51
+ if hide_commons
52
+ hide_list = ['or', 'the', 'of', 'a', 'if', 'to', 'and', 'in', 'is', 'are']
53
+ else
54
+ hide_list = []
55
+ end
56
+
57
+ w = Wc.new(ARGV[0], words, hide_list)
58
+
59
+
49
60
 
50
61
  if output == 'text'
51
62
  w.to_text
data/lib/wc.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  class Wc
2
2
  attr_reader :filename, :occurrences, :words
3
+ attr_accessor :hide_list
3
4
 
4
- def initialize(filename, words)
5
+ def initialize(filename, words, hide_list)
5
6
  @filename = filename
7
+ @hide_list = hide_list
6
8
  @occurrences = read
7
9
  @sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
8
10
  @words = words
9
11
  end
10
12
 
13
+
11
14
  def to_text
12
15
  if @words == -1
13
16
  @sorted.each { |elem|
@@ -51,7 +54,11 @@ class Wc
51
54
  File.open(@filename, "r") { |f|
52
55
  f.each_line { |line|
53
56
  words = line.split
54
- words.each { |w| occurrences[w] += 1 }
57
+ words.each { |w|
58
+ if ! hide_list.include?(w.downcase)
59
+ occurrences[w.downcase] += 1
60
+ end
61
+ }
55
62
  }
56
63
  }
57
64
  occurrences
data/wc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wc}
8
- s.version = "0.92.0"
8
+ s.version = "0.93.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-07-01}
12
+ s.date = %q{2010-07-02}
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: 367
4
+ hash: 363
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 92
8
+ - 93
9
9
  - 0
10
- version: 0.92.0
10
+ version: 0.93.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-07-01 00:00:00 +02:00
18
+ date: 2010-07-02 00:00:00 +02:00
19
19
  default_executable: wc
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency