char_detector 0.1.1 → 0.1.4

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
  SHA256:
3
- metadata.gz: bee172d7cfc38714ed519dfa6f709ddf52d1ffdc0c40bc23cf0480b545d865e7
4
- data.tar.gz: 636ba79305d27b11734a4e10644cf226364f0464423a4c4be9b6f75e50829426
3
+ metadata.gz: 15caadfd5032900dbf206ad06f7b73b71beab22fa7d04346ba3996ef93b6ea04
4
+ data.tar.gz: ec2649c362c86e24a02ade24fffa08409771434276e2da330b154ecbe5917bea
5
5
  SHA512:
6
- metadata.gz: 9566d3608f20d782b16e5abc63252c98efebae4436371a730fa47a4417f6dac4e91781f7287febff42793b7ffb5771a0a0f19b2d2bd55437a78e7077527b5182
7
- data.tar.gz: c16121f0a6b0ec8fc277d718bee151ff34901870a6506c9226fd71231513bbd8e9ac68d6f1834180cd7209d0686fd3b6842bd02ecd1e2d3a45867888b70c922e
6
+ metadata.gz: ba42566dbae9a7d0bf420153e75d9f86bccf4419c7e92e5ad1e48482fb849af7ad2cf365e46159f01f51df4da6c9ced7541d3cf297595e7fe4298832ff0bafac
7
+ data.tar.gz: e984bf6d160f7a7dba5b9542753eebc541a2ac162580a4fcb4140f22418043144401962262c2161984b6826823fb6afcea50b42d2d9e0fe8a4349941cb1b1362
data/README.md CHANGED
@@ -31,11 +31,6 @@ Ref: [ASCII table , ascii codes](https://theasciicode.com.ar/)
31
31
  + bundle gem char_detector
32
32
  + Test and fix and refactor
33
33
 
34
- + TODO refactor
35
- + TODO add features(If I have more requirements)
36
- + TODO [format output(refer to rubocop's output) Thanks Freebird](https://github.com/liijunwei/char_detector/issues/5)
37
- + TODO [Improve compatibility](https://github.com/liijunwei/char_detector/issues/4)
38
-
39
34
  ## Installation(WIP)
40
35
 
41
36
  Add this line to your application's Gemfile:
data/bin/char_detector CHANGED
@@ -29,16 +29,4 @@ OptionParser.new do |opts|
29
29
  end
30
30
  end.parse!
31
31
 
32
- info = {}
33
- info[:file] = options[:file]
34
- info[:result] = CharDetector::Engine.new(file: options[:file]).scan
35
-
36
- unless info[:result].empty?
37
- if options[:pretty]
38
- jj info
39
- else
40
- puts info.to_json
41
- end
42
- end
43
-
44
- exit 0
32
+ CharDetector::Cli.execute(options)
@@ -18,9 +18,21 @@ Gem::Specification.new do |spec|
18
18
  spec.metadata["source_code_uri"] = "https://github.com/liijunwei/char_detector"
19
19
  spec.metadata["changelog_uri"] = "https://github.com/liijunwei/char_detector"
20
20
 
21
+ ignored_files = %w[
22
+ .gitignore
23
+ .ruby-version
24
+ .tool-versions
25
+ bin/console
26
+ bin/setup
27
+ CODE_OF_CONDUCT.md
28
+ LICENSE.txt
29
+ Rakefile
30
+ ]
31
+
21
32
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|image|.github)/}) }.reject { |f| ignored_files.include?(f) }
23
34
  end
35
+
24
36
  spec.add_development_dependency "pry"
25
37
  spec.add_development_dependency "rake"
26
38
  spec.add_development_dependency "rspec"
@@ -0,0 +1,39 @@
1
+ module CharDetector
2
+ class Cli
3
+ def self.execute(options={})
4
+ new(options).run
5
+ end
6
+
7
+ attr_reader :options
8
+
9
+ def initialize(options={})
10
+ @options = options
11
+
12
+ if options[:file] && !File.exist?(options[:file])
13
+ warn("[fail] Can't find file: #{options[:file]}")
14
+ exit 1
15
+ end
16
+
17
+ if options.empty?
18
+ abort("[info] Pass -h for usage")
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ def run
24
+ info = {}
25
+ info[:file] = options[:file]
26
+ info[:result] = CharDetector::Engine.new(file: options[:file]).scan
27
+
28
+ unless info[:result].empty?
29
+ if options[:pretty]
30
+ jj info
31
+ else
32
+ puts info.to_json
33
+ end
34
+ end
35
+
36
+ exit 0
37
+ end
38
+ end
39
+ end
@@ -1,34 +1,21 @@
1
- class CharDetector::Engine
2
- def initialize(file:)
3
- @file = file
4
- end
5
-
6
- attr_reader :file
7
-
8
- def scan
9
- matches = []
10
-
11
- File.readlines(file).each_with_index do |line, index|
12
- scanned = trim_newline(line).scan(/\p{Cntrl}/)
13
- scanned -= trim_newline(line).scan(/\p{Space}/)
14
-
15
- next if scanned.empty?
1
+ module CharDetector
2
+ class Engine
3
+ def initialize(file:)
4
+ @file = file
5
+ end
16
6
 
17
- hash = {}
18
- hash[:line] = index + 1
19
- hash[:columns] = scanned.map { |e| line.index(e)+1 }
7
+ attr_reader :file
20
8
 
21
- matches << hash
22
- end
9
+ def scan
10
+ matches = []
23
11
 
24
- return matches
25
- end
12
+ File.readlines(file).each_with_index do |line, index|
13
+ if result = Line.new(index+1, line, /\p{Cntrl}/).scanline
14
+ matches << result
15
+ end
16
+ end
26
17
 
27
- def trim_newline(line)
28
- if line.end_with?("\n")
29
- line[0..-2]
30
- else
31
- line
18
+ return matches
32
19
  end
33
20
  end
34
21
  end
@@ -0,0 +1,47 @@
1
+ module CharDetector
2
+ class Line
3
+ def initialize(number, content, pattern)
4
+ @number = number
5
+ @content = content
6
+ @pattern = pattern
7
+ end
8
+
9
+ attr_reader :number, :content, :pattern
10
+
11
+ def scanline
12
+ return nil if matched_chars.empty? # TODO null object pattern?
13
+
14
+ hash = {}
15
+ hash[:line] = number
16
+ hash[:columns] = matched_columns
17
+
18
+ return hash
19
+ end
20
+
21
+ private
22
+
23
+ def matched_chars
24
+ all_matched_chars - matched_spaces
25
+ end
26
+
27
+ def all_matched_chars
28
+ trimmed_newline.scan(pattern)
29
+ end
30
+
31
+ def matched_spaces
32
+ trimmed_newline.scan(/\p{Space}/)
33
+ end
34
+
35
+ def matched_columns
36
+ matched_chars.map { |e| content.index(e)+1 }
37
+ end
38
+
39
+ def trimmed_newline
40
+ if content.end_with?("\n")
41
+ content[0..-2]
42
+ else
43
+ content
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module CharDetector
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/char_detector.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "char_detector/version"
2
+ require "char_detector/line"
2
3
  require "char_detector/engine"
4
+ require "char_detector/cli"
3
5
 
4
6
  module CharDetector
5
7
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: char_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - lijunwei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -60,25 +60,14 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".github/workflows/main.yml"
64
- - ".gitignore"
65
- - ".ruby-version"
66
- - ".tool-versions"
67
- - CODE_OF_CONDUCT.md
68
63
  - Gemfile
69
- - Gemfile.lock
70
- - LICENSE.txt
71
64
  - README.md
72
- - Rakefile
73
65
  - bin/char_detector
74
- - bin/console
75
- - bin/setup
76
66
  - char_detector.gemspec
77
- - image/Xnip2022-05-08_13-52-58.png
78
- - image/Xnip2022-05-08_14-10-52.png
79
- - image/Xnip2022-05-08_14-11-04.png
80
67
  - lib/char_detector.rb
68
+ - lib/char_detector/cli.rb
81
69
  - lib/char_detector/engine.rb
70
+ - lib/char_detector/line.rb
82
71
  - lib/char_detector/version.rb
83
72
  homepage: https://github.com/liijunwei/char_detector
84
73
  licenses:
@@ -103,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
92
  - !ruby/object:Gem::Version
104
93
  version: '0'
105
94
  requirements: []
106
- rubygems_version: 3.3.7
95
+ rubygems_version: 3.3.16
107
96
  signing_key:
108
97
  specification_version: 4
109
98
  summary: Initially used for detecting control character in markdown/ruby file.
@@ -1,32 +0,0 @@
1
- name: Ruby
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- pull_request:
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- name: Ruby ${{ matrix.ruby }}
14
- strategy:
15
- matrix:
16
- ruby:
17
- - '3.1.1'
18
- - '3.0.0'
19
- - '2.7.2'
20
- - '2.6.1'
21
- - '2.5.1'
22
- - '2.4.6'
23
-
24
- steps:
25
- - uses: actions/checkout@v2
26
- - name: Set up Ruby
27
- uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
- - name: Run the default task
32
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.1.1
data/.tool-versions DELETED
@@ -1,2 +0,0 @@
1
- ruby 3.1.1
2
-
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at ljw532344863@sina.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile.lock DELETED
@@ -1,40 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- char_detector (0.1.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- coderay (1.1.3)
10
- diff-lcs (1.5.0)
11
- method_source (1.0.0)
12
- pry (0.14.1)
13
- coderay (~> 1.1)
14
- method_source (~> 1.0)
15
- rake (13.0.6)
16
- rspec (3.11.0)
17
- rspec-core (~> 3.11.0)
18
- rspec-expectations (~> 3.11.0)
19
- rspec-mocks (~> 3.11.0)
20
- rspec-core (3.11.0)
21
- rspec-support (~> 3.11.0)
22
- rspec-expectations (3.11.0)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.11.0)
25
- rspec-mocks (3.11.1)
26
- diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.11.0)
28
- rspec-support (3.11.0)
29
-
30
- PLATFORMS
31
- ruby
32
-
33
- DEPENDENCIES
34
- char_detector!
35
- pry
36
- rake
37
- rspec
38
-
39
- BUNDLED WITH
40
- 2.3.7
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 lijunwei
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "char_detector"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- require "pry"
10
- Pry.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
Binary file
Binary file
Binary file