wc 0.94.2 → 0.95.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/wc +3 -1
- data/lib/wc.rb +65 -15
- data/wc.gemspec +8 -11
- metadata +7 -23
data/Rakefile
CHANGED
@@ -13,11 +13,11 @@ begin
|
|
13
13
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
14
|
# gem.add_development_dependency "getoptlong", ">=0"
|
15
15
|
gem.add_development_dependency "builder", ">=2.1.2"
|
16
|
-
gem.add_development_dependency "
|
16
|
+
gem.add_development_dependency "json_pure", ">=1.4.3"
|
17
17
|
|
18
18
|
# gem.add_dependency "getoptlong", ">=0"
|
19
|
-
gem.add_dependency "builder", ">=2.1.2"
|
20
|
-
gem.add_dependency "
|
19
|
+
#gem.add_dependency "builder", ">=2.1.2"
|
20
|
+
gem.add_dependency "json_pure", ">=1.4.3"
|
21
21
|
|
22
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
23
23
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.95.0
|
data/bin/wc
CHANGED
data/lib/wc.rb
CHANGED
@@ -1,22 +1,42 @@
|
|
1
1
|
class Wc
|
2
|
-
attr_reader :filename, :occurrences, :words
|
2
|
+
attr_reader :filename, :occurrences, :words, :no_autorun
|
3
3
|
attr_accessor :hide_list
|
4
4
|
|
5
|
-
def initialize(filename, words, hide_list)
|
5
|
+
# def initialize(filename, words, hide_list)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
# if ! filename.nil?
|
8
|
+
# @filename = filename
|
9
|
+
# @occurrences = read
|
10
|
+
# else
|
11
|
+
# @filename = STDIN
|
12
|
+
# @occurrences = feed
|
13
|
+
# end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
# @hide_list = hide_list
|
16
|
+
# @sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
|
17
|
+
# @words = words
|
18
|
+
#end
|
19
19
|
|
20
|
+
def initialize(filename=nil, options={})
|
21
|
+
@hide_list = options["hide_list"]
|
22
|
+
@words = options["words"]
|
23
|
+
@no_autorun = options["no_autorun"]
|
24
|
+
|
25
|
+
if ! @hide_list
|
26
|
+
@hide_list = []
|
27
|
+
end
|
28
|
+
p @no_autorun
|
29
|
+
if ! @no_autorun
|
30
|
+
if filename
|
31
|
+
@filename = filename
|
32
|
+
@occurrences = _read
|
33
|
+
else
|
34
|
+
@filename =STDIN
|
35
|
+
@occurrences = _feed
|
36
|
+
end
|
37
|
+
@sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
|
38
|
+
end
|
39
|
+
end
|
20
40
|
|
21
41
|
def to_text
|
22
42
|
if @words == -1
|
@@ -54,9 +74,39 @@ class Wc
|
|
54
74
|
ret
|
55
75
|
end
|
56
76
|
|
77
|
+
def read(filename)
|
78
|
+
@occurrences = Hash.new { |h, k| h[k] = 0 }
|
79
|
+
File.open(filename, "r") { |f|
|
80
|
+
f.each_line { |line|
|
81
|
+
words = line.split
|
82
|
+
words.each { |w|
|
83
|
+
if ! hide_list.include?(w.downcase)
|
84
|
+
@occurrences[w.downcase] += 1
|
85
|
+
end
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
@occurrences
|
90
|
+
end
|
91
|
+
|
92
|
+
def feed(line)
|
93
|
+
@occurrences = Hash.new { |h, k| h[k] = 0 }
|
94
|
+
words = line.split
|
95
|
+
words.each { |w|
|
96
|
+
if ! hide_list.include?(w.downcase)
|
97
|
+
@occurrences[w.downcase] += 1
|
98
|
+
end
|
99
|
+
}
|
100
|
+
@occurrences
|
101
|
+
end
|
102
|
+
|
103
|
+
def get()
|
104
|
+
@sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
|
105
|
+
end
|
106
|
+
|
57
107
|
private
|
58
108
|
|
59
|
-
def
|
109
|
+
def _read()
|
60
110
|
occurrences = Hash.new { |h, k| h[k] = 0 }
|
61
111
|
File.open(@filename, "r") { |f|
|
62
112
|
f.each_line { |line|
|
@@ -71,7 +121,7 @@ class Wc
|
|
71
121
|
occurrences
|
72
122
|
end
|
73
123
|
|
74
|
-
def
|
124
|
+
def _feed()
|
75
125
|
occurrences = Hash.new { |h, k| h[k] = 0 }
|
76
126
|
filename.each_line { |line|
|
77
127
|
words = line.split
|
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.
|
8
|
+
s.version = "0.95.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-
|
12
|
+
s.date = %q{2010-07-12}
|
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}
|
@@ -48,22 +48,19 @@ Gem::Specification.new do |s|
|
|
48
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
49
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
50
|
s.add_development_dependency(%q<builder>, [">= 2.1.2"])
|
51
|
-
s.add_development_dependency(%q<
|
52
|
-
s.add_runtime_dependency(%q<
|
53
|
-
s.add_runtime_dependency(%q<json>, [">= 1.4.3"])
|
51
|
+
s.add_development_dependency(%q<json_pure>, [">= 1.4.3"])
|
52
|
+
s.add_runtime_dependency(%q<json_pure>, [">= 1.4.3"])
|
54
53
|
else
|
55
54
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
56
55
|
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
57
|
-
s.add_dependency(%q<
|
58
|
-
s.add_dependency(%q<
|
59
|
-
s.add_dependency(%q<json>, [">= 1.4.3"])
|
56
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.3"])
|
57
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.3"])
|
60
58
|
end
|
61
59
|
else
|
62
60
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
63
61
|
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
64
|
-
s.add_dependency(%q<
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<json>, [">= 1.4.3"])
|
62
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.3"])
|
63
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.3"])
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 95
|
9
|
+
- 0
|
10
|
+
version: 0.95.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-
|
18
|
+
date: 2010-07-12 00:00:00 +02:00
|
19
19
|
default_executable: wc
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
type: :development
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: json_pure
|
53
53
|
prerelease: false
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
@@ -65,25 +65,9 @@ dependencies:
|
|
65
65
|
type: :development
|
66
66
|
version_requirements: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: json_pure
|
69
69
|
prerelease: false
|
70
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 15
|
76
|
-
segments:
|
77
|
-
- 2
|
78
|
-
- 1
|
79
|
-
- 2
|
80
|
-
version: 2.1.2
|
81
|
-
type: :runtime
|
82
|
-
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: json
|
85
|
-
prerelease: false
|
86
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
87
71
|
none: false
|
88
72
|
requirements:
|
89
73
|
- - ">="
|
@@ -95,7 +79,7 @@ dependencies:
|
|
95
79
|
- 3
|
96
80
|
version: 1.4.3
|
97
81
|
type: :runtime
|
98
|
-
version_requirements: *
|
82
|
+
version_requirements: *id004
|
99
83
|
description: your ruby word counter experience
|
100
84
|
email: thesp0nge@gmail.com
|
101
85
|
executables:
|