char_detector 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 812bbf7902155754e4632629400a6d6c1ce2e8c20ee33057c70fa0093d2b58b2
4
- data.tar.gz: 32de51f941e5603a2d339641125d68a891c3b3c2dd22b33948e88b22a751277f
3
+ metadata.gz: ca2acf1488e57bed7877e23a5d60dbf70f2282ee2d93aff26ea8dd61ea100a94
4
+ data.tar.gz: f17473a5f1fb144af70571af7e324cf91d1d686f77b97ae0b882e8bd568389ca
5
5
  SHA512:
6
- metadata.gz: fb1bf08eb9984f91f17ef1e08a8fb1c02d362c54bf9a418c121613ef37b62a65b5cae4c9e243f5b57beba1a3755da97e5b5923ec6dbee42a2d2d14d9197c8b31
7
- data.tar.gz: 703e38057ceb2a41faa3afca1d65dd13c636a5f393ac3c7286936714ffa33aed7bc3cce0cad3e7c41e51d24a24f18d78a32dd46bf4fe840b607e6bb4083d40fa
6
+ metadata.gz: 1cc8d332834b9fcccc8e826ec30b73066ef6643056b0257435ed7e1133ffac2dd4b395211aa74189b87ef4509bb2f5649cd4747c55d97e1349474c34de3c5d48
7
+ data.tar.gz: 7b3672e43019af63ccbecfda4229ae84313915b9cca8f031cd2a93e5524f3ba030193a5876d7cce233d8784c5b834cdac4a6524e2ba718fe648f25d64b22266e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- char_detector (0.1.2)
4
+ char_detector (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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"
@@ -1,37 +1,39 @@
1
- class CharDetector::Cli
2
- def self.execute(options={})
3
- new(options).run
4
- end
1
+ module CharDetector
2
+ class Cli
3
+ def self.execute(options={})
4
+ new(options).run
5
+ end
5
6
 
6
- attr_reader :options
7
+ attr_reader :options
7
8
 
8
- def initialize(options={})
9
- @options = options
9
+ def initialize(options={})
10
+ @options = options
10
11
 
11
- if options[:file] && !File.exist?(options[:file])
12
- warn("[fail] Can't find file: #{options[:file]}")
13
- exit 1
14
- end
12
+ if options[:file] && !File.exist?(options[:file])
13
+ warn("[fail] Can't find file: #{options[:file]}")
14
+ exit 1
15
+ end
15
16
 
16
- if options.empty?
17
- abort("[info] Pass -h for usage")
18
- exit 1
17
+ if options.empty?
18
+ abort("[info] Pass -h for usage")
19
+ exit 1
20
+ end
19
21
  end
20
- end
21
22
 
22
- def run
23
- info = {}
24
- info[:file] = options[:file]
25
- info[:result] = CharDetector::Engine.new(file: options[:file]).scan
23
+ def run
24
+ info = {}
25
+ info[:file] = options[:file]
26
+ info[:result] = CharDetector::Engine.new(file: options[:file]).scan
26
27
 
27
- unless info[:result].empty?
28
- if options[:pretty]
29
- jj info
30
- else
31
- puts info.to_json
28
+ unless info[:result].empty?
29
+ if options[:pretty]
30
+ jj info
31
+ else
32
+ puts info.to_json
33
+ end
32
34
  end
33
- end
34
35
 
35
- exit 0
36
+ exit 0
37
+ end
36
38
  end
37
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.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/char_detector.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "char_detector/version"
2
+ require "char_detector/line"
2
3
  require "char_detector/engine"
3
4
  require "char_detector/cli"
4
5
 
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.2
4
+ version: 0.1.3
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-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -60,26 +60,15 @@ 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
64
  - Gemfile.lock
70
- - LICENSE.txt
71
65
  - README.md
72
- - Rakefile
73
66
  - bin/char_detector
74
- - bin/console
75
- - bin/setup
76
67
  - 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
68
  - lib/char_detector.rb
81
69
  - lib/char_detector/cli.rb
82
70
  - lib/char_detector/engine.rb
71
+ - lib/char_detector/line.rb
83
72
  - lib/char_detector/version.rb
84
73
  homepage: https://github.com/liijunwei/char_detector
85
74
  licenses:
@@ -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/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