wc 0.10.0 → 0.20.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/Rakefile +8 -0
  2. data/VERSION +1 -1
  3. data/bin/wc +26 -4
  4. data/lib/wc.rb +12 -16
  5. data/wc.gemspec +69 -0
  6. metadata +68 -3
data/Rakefile CHANGED
@@ -11,6 +11,14 @@ begin
11
11
  gem.homepage = "http://github.com/thesp0nge/wc"
12
12
  gem.authors = ["Paolo Perego"]
13
13
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem.add_development_dependency "getoptlong", ">=0"
15
+ gem.add_development_dependency "builder", ">=2.1.2"
16
+ gem.add_development_dependency "json", ">=1.4.3"
17
+
18
+ # gem.add_dependency "getoptlong", ">=0"
19
+ gem.add_dependency "builder", ">=2.1.2"
20
+ gem.add_dependency "json", ">=1.4.3"
21
+
14
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
23
  end
16
24
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.0
1
+ 0.20.0
data/bin/wc CHANGED
@@ -5,25 +5,47 @@ require 'rdoc/usage'
5
5
 
6
6
  opts = GetoptLong.new(
7
7
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
8
- [ '--version', '-v', GetoptLong::NO_ARGUMENT ]
8
+ [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
9
+ [ '--json', '-j', GetoptLong::NO_ARGUMENT ],
10
+ [ '--xml', '-x', GetoptLong::NO_ARGUMENT ]
9
11
  )
10
12
 
13
+ output = 'text'
14
+
15
+ begin
11
16
  opts.each do |opt, arg|
12
17
  case opt
13
- when '--help'
18
+ when '--help'
14
19
  RDoc::usage
15
20
  exit 0
16
21
  when '--version'
17
22
  @version = File.exist?('VERSION') ? File.read('VERSION') : ""
18
23
  puts @version
19
24
  exit 0
25
+ when '--json'
26
+ output = 'json'
20
27
  end
21
28
  end
29
+ rescue
30
+ exit 0
31
+ end
32
+
22
33
 
23
34
  if ARGV.length != 1
24
35
  raise "Please provide a filename."
25
36
  exit 0
26
37
  end
27
38
 
28
- w = Wc.new(ARGV.shift)
29
- w.to_text
39
+ w = Wc.new(ARGV[0])
40
+
41
+ if output == 'text'
42
+ w.to_text
43
+ end
44
+ if output == 'json'
45
+ puts 'json support is coming soon...'
46
+ end
47
+ if output == 'xml'
48
+ puts 'xml support is coming soon...'
49
+ end
50
+
51
+ exit 0
data/lib/wc.rb CHANGED
@@ -4,30 +4,26 @@ class Wc
4
4
  def initialize(filename)
5
5
  @filename = filename
6
6
  @hash = read
7
- @hash.sort{|a,b| a[1]<=>b[1]}
7
+ Array(hash).sort { |one, two| -(one <=> two) }
8
+
8
9
  end
9
10
 
10
11
  def to_text
11
- @hash.each { |elem|
12
- puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
13
- }
12
+ @hash.each { |elem|
13
+ puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
14
+ }
14
15
  end
15
16
 
16
17
  private
17
18
 
18
19
  def read()
19
- hash = Hash.new
20
- f = File.open(ARGV[0], "r")
21
- f.each_line { |line|
22
- words = line.split
23
- words.each { |w|
24
- if hash.has_key?(w)
25
- hash[w] = hash[w] + 1
26
- else
27
- hash[w] = 1
28
- end
29
- }
30
- }
20
+ hash = Hash.new { |h, k| h[k] = 0 }
21
+ File.open(ARGV[0], "r") { |f|
22
+ f.each_line { |line|
23
+ words = line.split
24
+ words.each { |w| hash[w] += 1 }
25
+ }
26
+ }
31
27
  hash
32
28
  end
33
29
 
data/wc.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wc}
8
+ s.version = "0.20.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paolo Perego"]
12
+ s.date = %q{2010-06-10}
13
+ s.default_executable = %q{wc}
14
+ s.description = %q{your ruby word counter experience}
15
+ s.email = %q{thesp0nge@gmail.com}
16
+ s.executables = ["wc"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/wc",
29
+ "lib/wc.rb",
30
+ "test/helper.rb",
31
+ "test/test_wc.rb",
32
+ "wc.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/thesp0nge/wc}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{your ruby word counter experience}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_wc.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<builder>, [">= 2.1.2"])
51
+ s.add_development_dependency(%q<json>, [">= 1.4.3"])
52
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
53
+ s.add_runtime_dependency(%q<json>, [">= 1.4.3"])
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
57
+ s.add_dependency(%q<json>, [">= 1.4.3"])
58
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
59
+ s.add_dependency(%q<json>, [">= 1.4.3"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
63
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
64
+ s.add_dependency(%q<json>, [">= 1.4.3"])
65
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
66
+ s.add_dependency(%q<json>, [">= 1.4.3"])
67
+ end
68
+ end
69
+
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: 55
4
+ hash: 79
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 10
8
+ - 20
9
9
  - 0
10
- version: 0.10.0
10
+ version: 0.20.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paolo Perego
@@ -32,6 +32,70 @@ dependencies:
32
32
  version: "0"
33
33
  type: :development
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: builder
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 2
46
+ - 1
47
+ - 2
48
+ version: 2.1.2
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: json
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 1
60
+ segments:
61
+ - 1
62
+ - 4
63
+ - 3
64
+ version: 1.4.3
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: builder
69
+ prerelease: false
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
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 1
92
+ segments:
93
+ - 1
94
+ - 4
95
+ - 3
96
+ version: 1.4.3
97
+ type: :runtime
98
+ version_requirements: *id005
35
99
  description: your ruby word counter experience
36
100
  email: thesp0nge@gmail.com
37
101
  executables:
@@ -52,6 +116,7 @@ files:
52
116
  - lib/wc.rb
53
117
  - test/helper.rb
54
118
  - test/test_wc.rb
119
+ - wc.gemspec
55
120
  has_rdoc: true
56
121
  homepage: http://github.com/thesp0nge/wc
57
122
  licenses: []