vocab_counter 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,11 +18,8 @@ mat,1
18
18
 
19
19
  * Fork the project.
20
20
  * Make your feature addition or bug fix.
21
- * Add tests for it. This is important so I don't break it in a
22
- future version unintentionally.
23
- * Commit, do not mess with rakefile, version, or history.
24
- (if you want to have your own version, that is fine but
25
- bump version in a commit by itself I can ignore when I pull)
21
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
26
23
  * Send me a pull request. Bonus points for topic branches.
27
24
 
28
25
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 1.0.0
@@ -3,12 +3,11 @@
3
3
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
4
  require 'vocab_counter'
5
5
 
6
- unless File.exists?(ARGV[0].to_s)
7
- puts "Vocab counter: please specify a file"
8
- Process.exit
9
- end
6
+ v = VocabCounter.new
10
7
 
11
- file = File.open(ARGV[0])
8
+ ARGF.each do |line|
9
+ v.count(line)
10
+ end
12
11
 
13
- puts VocabCounter.count(file.read)
12
+ puts v.report
14
13
 
@@ -1,16 +1,21 @@
1
1
  class VocabCounter
2
2
 
3
- def self.count(input)
4
- input.downcase!
5
- input.gsub!(/[^a-z0-9']/, ' ')
6
- input.gsub!(/\s'|'\s/, ' ')
7
- count = Hash.new(0)
8
- input.split(/\s+/).each do |term|
9
- count[term.to_sym] += 1
3
+ def initialize
4
+ @count = Hash.new(0)
5
+ end
6
+
7
+ def count(line)
8
+ line.downcase!
9
+ line.gsub!(/[^a-z0-9']/, ' ')
10
+ line.gsub!(/\s'|'\s/, ' ')
11
+ line.split(/\s+/).each do |term|
12
+ @count[term.to_sym] += 1
10
13
  end
14
+ end
11
15
 
16
+ def report
12
17
  out = ""
13
- count.sort { |a,b| b[1] <=> a[1] }.each do |k,v|
18
+ @count.sort { |a,b| b[1] <=> a[1] }.each do |k,v|
14
19
  out << "#{k.to_s},#{v}\n"
15
20
  end
16
21
  out
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vocab_counter}
8
- s.version = "0.1.1"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julian Burgess"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vocab_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Burgess