typo_detector 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 +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/bin/typo_detector +5 -0
- data/lib/typo_detector.rb +5 -0
- data/lib/typo_detector/command.rb +104 -0
- data/lib/typo_detector/version.rb +3 -0
- data/typo_detector.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bf40733f5a08b0e50d645f974228a734c64c79ea
|
|
4
|
+
data.tar.gz: eca6eae7542e7d8ebf2478b9b0572cbcc4d4c489
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: eb2d23efaa490e3f310539055a9125edadc153bc6d7c67f149988b8931113606828d9472cada68d06431fe92ff4dd74d687d8397b4199b67aecb0dc5bd56ee71
|
|
7
|
+
data.tar.gz: b414639df1712cecd832c4d11ca8fd127877199a20144d3e36affd74e3e93e5b37b318114e03963602deefb8e18bc2889ea6f31329439a680d169c7dbc35a2d6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Masafumi Yokoyama <myokoym@gmail.com>
|
|
2
|
+
|
|
3
|
+
zlib License
|
|
4
|
+
|
|
5
|
+
This software is provided 'as-is', without any express or implied
|
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
|
7
|
+
arising from the use of this software.
|
|
8
|
+
|
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
|
11
|
+
freely, subject to the following restrictions:
|
|
12
|
+
|
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
14
|
+
claim that you wrote the original software. If you use this software
|
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
|
16
|
+
appreciated but is not required.
|
|
17
|
+
|
|
18
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
19
|
+
misrepresented as being the original software.
|
|
20
|
+
|
|
21
|
+
3. This notice may not be removed or altered from any source
|
|
22
|
+
distribution.
|
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# TypoDetector
|
|
2
|
+
|
|
3
|
+
A detective tool for typo.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'typo_detector'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install typo_detector
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Files
|
|
24
|
+
|
|
25
|
+
$ typo_detector [FILE]...
|
|
26
|
+
|
|
27
|
+
### Git repositories
|
|
28
|
+
|
|
29
|
+
$ typo_detector -g [DIRECTORY]...
|
|
30
|
+
|
|
31
|
+
## Authors
|
|
32
|
+
|
|
33
|
+
* Masafumi Yokoyama `<myokoym@gmail.com>`
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
This software is distributed under the zlib license.
|
|
38
|
+
|
|
39
|
+
See LICENSE.txt for details.
|
|
40
|
+
|
|
41
|
+
(Masafumi Yokoyama has a right to change the license including
|
|
42
|
+
contributed patches.)
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
1. Fork it ( https://github.com/myokoym/typo_detector/fork )
|
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/typo_detector
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require "optparse"
|
|
3
|
+
require "typo_detector/version"
|
|
4
|
+
|
|
5
|
+
module TypoDetector
|
|
6
|
+
class Command
|
|
7
|
+
def initialize(arguments)
|
|
8
|
+
@options = parse_options(arguments)
|
|
9
|
+
@paths = arguments
|
|
10
|
+
@word_counts = {}
|
|
11
|
+
@word_resources = {}
|
|
12
|
+
@max_width = 0
|
|
13
|
+
@scan_pattern = scan_pattern
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def run
|
|
17
|
+
index
|
|
18
|
+
filter
|
|
19
|
+
show
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def parse_options(arguments)
|
|
24
|
+
usage = "Usage: typo_detector [OPTIONS] [FILE]..."
|
|
25
|
+
parser = OptionParser.new(usage)
|
|
26
|
+
parser.version = TypoDetector::VERSION
|
|
27
|
+
|
|
28
|
+
options = {}
|
|
29
|
+
parser.on("-g", "--git",
|
|
30
|
+
"Use `git ls-files` with a directory.") do |boolean|
|
|
31
|
+
options[:git] = boolean
|
|
32
|
+
end
|
|
33
|
+
parser.on("-_",
|
|
34
|
+
"Split by '_'.") do |boolean|
|
|
35
|
+
options[:_] = boolean
|
|
36
|
+
end
|
|
37
|
+
parser.parse!(arguments)
|
|
38
|
+
|
|
39
|
+
options
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def scan_pattern
|
|
43
|
+
if @options[:_]
|
|
44
|
+
/[A-Za-z0-9]+/
|
|
45
|
+
else
|
|
46
|
+
/\w+/
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def index
|
|
51
|
+
each_files do |path, dirname|
|
|
52
|
+
words = nil
|
|
53
|
+
begin
|
|
54
|
+
words = File.read(path).scan(@scan_pattern)
|
|
55
|
+
rescue
|
|
56
|
+
$stderr.puts("#{$!.message}: <#{path}>")
|
|
57
|
+
next
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
words.each do |word|
|
|
61
|
+
@word_counts[word] ||= 0
|
|
62
|
+
@word_counts[word] += 1
|
|
63
|
+
if dirname
|
|
64
|
+
@word_resources[word] = File.join(dirname, path)
|
|
65
|
+
else
|
|
66
|
+
@word_resources[word] = path
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
width = words.collect {|word| word.size}.max || 0
|
|
71
|
+
@max_width = width if width > @max_width
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def filter
|
|
76
|
+
@word_counts.select! do |word, count|
|
|
77
|
+
count == 1
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def show
|
|
82
|
+
@word_counts.keys.sort.sort_by {|word, count| @word_resources[word]}.each do |word|
|
|
83
|
+
puts "#{"%-#{@max_width}s" % word}: #{@word_resources[word]}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def each_files
|
|
88
|
+
if @options[:git]
|
|
89
|
+
@paths.each do |git_dir_path|
|
|
90
|
+
git_dir_basename = File.basename(git_dir_path)
|
|
91
|
+
FileUtils.cd(git_dir_path) do
|
|
92
|
+
`git ls-files`.split(/\n/).each do |path|
|
|
93
|
+
yield(path, git_dir_basename)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
else
|
|
98
|
+
@paths.each do |path|
|
|
99
|
+
yield(path)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -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 'typo_detector/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "typo_detector"
|
|
8
|
+
spec.version = TypoDetector::VERSION
|
|
9
|
+
spec.authors = ["Masafumi Yokoyama"]
|
|
10
|
+
spec.email = ["myokoym@gmail.com"]
|
|
11
|
+
spec.summary = %q{A detective tool for typo.}
|
|
12
|
+
spec.description = spec.summary
|
|
13
|
+
spec.homepage = "https://github.com/myokoym/typo_detector"
|
|
14
|
+
spec.license = "zlib"
|
|
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")
|
|
22
|
+
spec.add_development_dependency("rake")
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: typo_detector
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Masafumi Yokoyama
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-15 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: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: A detective tool for typo.
|
|
42
|
+
email:
|
|
43
|
+
- myokoym@gmail.com
|
|
44
|
+
executables:
|
|
45
|
+
- typo_detector
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/typo_detector
|
|
55
|
+
- lib/typo_detector.rb
|
|
56
|
+
- lib/typo_detector/command.rb
|
|
57
|
+
- lib/typo_detector/version.rb
|
|
58
|
+
- typo_detector.gemspec
|
|
59
|
+
homepage: https://github.com/myokoym/typo_detector
|
|
60
|
+
licenses:
|
|
61
|
+
- zlib
|
|
62
|
+
metadata: {}
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubyforge_project:
|
|
79
|
+
rubygems_version: 2.2.2
|
|
80
|
+
signing_key:
|
|
81
|
+
specification_version: 4
|
|
82
|
+
summary: A detective tool for typo.
|
|
83
|
+
test_files: []
|
|
84
|
+
has_rdoc:
|