wfq 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/bin/wfq +9 -0
- data/lib/wfq.rb +32 -0
- data/lib/wfq/version.rb +3 -0
- data/sample.txt +13426 -0
- data/spec/fixture.txt +1 -0
- data/spec/wfq/word_frequency_spec.rb +61 -0
- data/wfq.gemspec +23 -0
- metadata +88 -0
data/spec/fixture.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is a fixture file.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'wfq'
|
2
|
+
|
3
|
+
describe Wfq::WordFrequency do
|
4
|
+
let(:wf) { Wfq::WordFrequency.new }
|
5
|
+
|
6
|
+
describe '#read' do
|
7
|
+
it 'converts a text file into a text string' do
|
8
|
+
text = wf.read('spec/fixture.txt')
|
9
|
+
expect(text).to be_a String
|
10
|
+
expect(text).to eq 'This is a fixture file.'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#clean' do
|
15
|
+
it 'lowercases text' do
|
16
|
+
text = wf.clean('LOWERCASE')
|
17
|
+
expect(text).to eq 'lowercase'
|
18
|
+
end
|
19
|
+
it 'removes punctuation' do
|
20
|
+
text = wf.clean('!c,a.l?m-')
|
21
|
+
expect(text).to eq 'calm'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#count' do
|
26
|
+
context 'with empty string' do
|
27
|
+
it 'raises an ArgumentError' do
|
28
|
+
expect{ wf.count('') }.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context 'with a sentence' do
|
32
|
+
it 'returns a hash and counts word frequency' do
|
33
|
+
count = wf.count('fuzzy wuzzy was a bear fuzzy wuzzy had no hair')
|
34
|
+
expect(count).to be_a Hash
|
35
|
+
expect(count).to eq({
|
36
|
+
'fuzzy' => 2,
|
37
|
+
'wuzzy' => 2,
|
38
|
+
'was' => 1,
|
39
|
+
'a' => 1,
|
40
|
+
'bear' => 1,
|
41
|
+
'had' => 1,
|
42
|
+
'no' => 1,
|
43
|
+
'hair' => 1
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#print' do
|
50
|
+
it 'outputs the count hash to the console' do
|
51
|
+
hash = { hello: 1 }
|
52
|
+
expect{ wf.print(hash) }.to output("hello: #{'#'*50} 1\n").to_stdout
|
53
|
+
end
|
54
|
+
it 'outputs in descending order' do
|
55
|
+
hash = { two: 2, three: 3, one: 1 }
|
56
|
+
expect{ wf.print(hash) }.to output("three: #{'#'*50} 3\n"\
|
57
|
+
"two: #{'#'*33} 2\n"\
|
58
|
+
"one: #{'#'*16} 1\n").to_stdout
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/wfq.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wfq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wfq"
|
8
|
+
spec.version = Wfq::VERSION
|
9
|
+
spec.authors = ["Josh Langholtz"]
|
10
|
+
spec.email = ["josh.langholtz@validic.com"]
|
11
|
+
spec.summary = %q{Word frequency count from a text file.}
|
12
|
+
spec.description = %q{Simple ruby program to count the word frequency in a file.}
|
13
|
+
spec.homepage = "https://www.github.com/jjlangholtz/wfq"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wfq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Langholtz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Simple ruby program to count the word frequency in a file.
|
42
|
+
email:
|
43
|
+
- josh.langholtz@validic.com
|
44
|
+
executables:
|
45
|
+
- wfq
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/wfq
|
55
|
+
- lib/wfq.rb
|
56
|
+
- lib/wfq/version.rb
|
57
|
+
- sample.txt
|
58
|
+
- spec/fixture.txt
|
59
|
+
- spec/wfq/word_frequency_spec.rb
|
60
|
+
- wfq.gemspec
|
61
|
+
homepage: https://www.github.com/jjlangholtz/wfq
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Word frequency count from a text file.
|
85
|
+
test_files:
|
86
|
+
- spec/fixture.txt
|
87
|
+
- spec/wfq/word_frequency_spec.rb
|
88
|
+
has_rdoc:
|