word_counter 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ade1c307df08ce4f7d5fcb3d532088273a8742b5
4
- data.tar.gz: c3442e5db2e4ce1e5d251453df1a2d424aa49fb7
3
+ metadata.gz: 12a0d420b2bc220bf3303c5b2a25939dd7a913a9
4
+ data.tar.gz: 820f8f29ff3a54921a730b3ef67eaee8ed8cb73b
5
5
  SHA512:
6
- metadata.gz: 7c1ea12f35aab39d409c8682c61d48cff3ba0998fd2018202d20f21682a0287f6893bff7efc961738f367670281c0af9aec1cf96d7b83d41094ccf56949ab69c
7
- data.tar.gz: c78ab4a91fa093168ef1c0b8cff646de337cb233d334362002d6074c6f50730ffb88c2a43938535a812d5d48e037db6511174a3b02b97045217463bc6a28d21a
6
+ metadata.gz: 1b0c8ac6c477814521d9e45067db7bf92c0122acefd1a40268edca6c4e66d0e9e3db44edc199b2f90666a4f47dc5fd4f7e442db990992b80244955878eac8798
7
+ data.tar.gz: bef591f767adb60f0c9e6188eaefafb9aab123ee6810bcafe506cb2fc4c2572c0fd0943857b88634fa76e1bf166bc3e7c3f3f915ffec59b1cfdd39b19ffe0203
data/README.md CHANGED
@@ -56,10 +56,16 @@ Use the `-s` switch to also report which lines contained the counted word (can r
56
56
  1: This domain is established to be used for illustrative examples in documents. You may use this
57
57
  2: domain in examples without prior coordination or asking for permission.
58
58
 
59
+ ## Options
60
+
61
+ -c Colorize output
62
+ -s Show sentences containing the words in question
63
+
59
64
  ## Roadmap
60
65
 
61
- - Color
62
- - More flexible options
66
+ - Make color optional and not-default (-c switch)
67
+ - Ignore common words (a, for, it, the, of, etc.
68
+ - Ignore case
63
69
 
64
70
  ## Contributing
65
71
 
@@ -2,7 +2,12 @@
2
2
 
3
3
  require 'word_counter'
4
4
 
5
- i = ARGV.index('-s') || -1
6
- show_sentences = ARGV.delete_at i if i >= 0
7
- wc = WordCounter.new ARGV[0], show_sentences
5
+ def get_switch name
6
+ i = ARGV.index(name) || -1
7
+ ARGV.delete_at i if i >= 0
8
+ end
9
+
10
+ show_sentences = get_switch '-s'
11
+ colorize = get_switch '-c'
12
+ wc = WordCounter.new ARGV[0], show_sentences, colorize
8
13
  wc.report
@@ -14,9 +14,10 @@ class WordCounter
14
14
  #
15
15
  # @param filename [String] The path and filename of the file to analyze
16
16
  # @param show_sentences [Boolean] (default: false) If true, WordCounter will print out the sentences which contain the counted word in question
17
- def initialize arg, show_sentences = false
17
+ def initialize arg, show_sentences = false, colorize = false
18
18
  raise ArgumentError, "Please supply a URL or file path." unless arg
19
- @show_sentences = true if show_sentences
19
+ @show_sentences = show_sentences
20
+ @colorize = colorize
20
21
 
21
22
  begin
22
23
  # try to open it as a file
@@ -35,30 +36,30 @@ class WordCounter
35
36
  end
36
37
 
37
38
 
38
- def colorize str
39
- str.to_s.green.bold
39
+ def colorize str, options
40
+ @colorize ? str.to_s.colorize(options) : str
40
41
  end
41
42
 
42
43
 
43
44
  ##
44
45
  # Prints a report to stdout
45
46
  def report
46
- hashified_words_with_sorted_lines = @hashified_words.each do |word, data|
47
- # data[:lines].sort
48
- end
47
+ # hashified_words_with_sorted_lines = @hashified_words.each do |word, data|
48
+ # data[:lines].sort
49
+ # end
49
50
 
50
- sorted_hash = hashified_words_with_sorted_lines.sort_by { |word, data|
51
+ sorted_hash = @hashified_words.sort_by { |word, data|
51
52
  [-data[:count], word]
52
53
  }
53
54
 
54
55
  puts 'Results:'
55
56
  sorted_hash.each do |word, data|
56
- puts colorize "#{data[:count]} #{word}"
57
+ puts(colorize "#{data[:count]} #{word}", color: :green, mode: :bold)
57
58
 
58
59
  i = 0
59
60
  lines = data[:lines].map { |l|
60
61
  i += 1
61
- "#{i.to_s.red}: #{l}"
62
+ "#{colorize i, color: :red}: #{l}"
62
63
  }.join("\n ")
63
64
 
64
65
  puts " #{lines}" if show_sentences?
@@ -1,3 +1,3 @@
1
1
  class WordCounter
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - trevor bortins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler