regexp_scan 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +9 -0
- data/bin/reg-scan +29 -0
- data/input.text +3 -0
- data/lib/regexp_scan.rb +5 -0
- data/lib/regexp_scan/scanner.rb +29 -0
- data/lib/regexp_scan/version.rb +3 -0
- data/regexp_scan.gemspec +24 -0
- data/test/minitest_helper.rb +4 -0
- data/test/test_scanner.rb +53 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a33631c0557a7eb5028d0e212b5d26796db163d5
|
4
|
+
data.tar.gz: 364143d52d8cd12669c7c06070ab61e0c43ebc14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46dc3459748b5b4b78d3ece9fa1eb8eb134ae19ffed1f97d74136888dcee9762116e4dbd1fedaacdec72405cf75bac572a09584a8b8777be177d8a5c39b23baf
|
7
|
+
data.tar.gz: becf819de623d0a8315dd971b9e71c2c59791bd4305b69a8987b212bd624fa1a0f9581baf479897ff40783aeabb472741229db38bf0a21faf48e21e1552b9dc8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Shinya131
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# RegexpScan
|
2
|
+
|
3
|
+
This is ruby gem.
|
4
|
+
This gem provide `String#scan` for CLI.
|
5
|
+
|
6
|
+
Strings filter by Regexp.
|
7
|
+
Pickup strings that match the regular expression from source string.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'regexp_scan'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install regexp_scan
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Use for `ARGV`
|
28
|
+
|
29
|
+
```shell
|
30
|
+
$ reg-scan "\d+" "[111,222,333]"
|
31
|
+
111
|
32
|
+
222
|
33
|
+
333
|
34
|
+
```
|
35
|
+
|
36
|
+
### Use for `STDIN`
|
37
|
+
|
38
|
+
```shell
|
39
|
+
$ cat input.text
|
40
|
+
[111,222]
|
41
|
+
[333,444]
|
42
|
+
[555]
|
43
|
+
|
44
|
+
$ cat input.text | ./bin/reg-scan "\d+"
|
45
|
+
111
|
46
|
+
222
|
47
|
+
333
|
48
|
+
444
|
49
|
+
555
|
50
|
+
```
|
51
|
+
|
52
|
+
### option: `-o` only first
|
53
|
+
|
54
|
+
|
55
|
+
```shell
|
56
|
+
$ reg-scan -o "\d+" "[111,222,333]"
|
57
|
+
111
|
58
|
+
```
|
59
|
+
s
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/[my-github-username]/regexp_scan/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/reg-scan
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'regexp_scan'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
params = ARGV.getopts('o')
|
8
|
+
|
9
|
+
@filter_regexp = /#{ARGV[0]}/
|
10
|
+
@source_string = ARGV[1]
|
11
|
+
@only_first = params['o'] || false
|
12
|
+
|
13
|
+
def regexp_scan
|
14
|
+
filterd_strings = RegexpScan::Scanner.new(@filter_regexp).execute(@source_string)
|
15
|
+
|
16
|
+
if @only_first
|
17
|
+
puts filterd_strings.first
|
18
|
+
else
|
19
|
+
puts filterd_strings
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if @source_string
|
24
|
+
regexp_scan
|
25
|
+
else
|
26
|
+
while @source_string = $stdin.gets do
|
27
|
+
regexp_scan
|
28
|
+
end
|
29
|
+
end
|
data/input.text
ADDED
data/lib/regexp_scan.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class RegexpScan::Scanner
|
2
|
+
def initialize(filter_regexp)
|
3
|
+
@filter_regexp = to_regexp(filter_regexp)
|
4
|
+
validation!
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute(string)
|
8
|
+
string.scan(/#{@filter_regexp}/)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def to_regexp(string_or_regexp)
|
14
|
+
case string_or_regexp
|
15
|
+
when String
|
16
|
+
Regexp.new(string_or_regexp)
|
17
|
+
when Regexp
|
18
|
+
string_or_regexp
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def validation!
|
25
|
+
unless @filter_regexp.is_a?(Regexp)
|
26
|
+
raise ArgumentError.new('Expect Argument is Regexp or String')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/regexp_scan.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'regexp_scan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "regexp_scan"
|
8
|
+
spec.version = RegexpScan::VERSION
|
9
|
+
spec.authors = ["Shinya131"]
|
10
|
+
spec.email = ["nagai3mt5b@gmail.com"]
|
11
|
+
spec.summary = "Strings filter by Regexp."
|
12
|
+
spec.description = "This gem provide `String#scan` for CLI. Pickup strings that match the regular expression from source string."
|
13
|
+
spec.homepage = "https://github.com/Shinya131/regexp_scan"
|
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
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe RegexpScan::Scanner do
|
4
|
+
describe '#initialize' do
|
5
|
+
describe 'initialize by String' do
|
6
|
+
before do
|
7
|
+
@scanner = RegexpScan::Scanner.new('\d+')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'filtering only match string' do
|
11
|
+
assert @scanner.execute('1111,2222,') == ['1111', '2222']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'initialize by Regexp' do
|
16
|
+
before do
|
17
|
+
@scanner = RegexpScan::Scanner.new(/\d+/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'filtering only match string' do
|
21
|
+
assert @scanner.execute('1111,2222,') == ['1111', '2222']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'initilaize by not Regxp and not String' do
|
26
|
+
it 'raise' do
|
27
|
+
assert_raises(ArgumentError){ RegexpScan::Scanner.new(111122223333) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#execute' do
|
33
|
+
describe 'string. that include match string' do
|
34
|
+
before do
|
35
|
+
@scanner = RegexpScan::Scanner.new('\d+')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'array of match string' do
|
39
|
+
assert @scanner.execute('1111,2222,3333') == ['1111', '2222', '3333']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'string. that does not include match string' do
|
44
|
+
before do
|
45
|
+
@scanner = RegexpScan::Scanner.new('\d+')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'empty array' do
|
49
|
+
assert @scanner.execute('aaaa,bbbb,cccc').empty?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: regexp_scan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shinya131
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-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: '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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem provide `String#scan` for CLI. Pickup strings that match the
|
56
|
+
regular expression from source string.
|
57
|
+
email:
|
58
|
+
- nagai3mt5b@gmail.com
|
59
|
+
executables:
|
60
|
+
- reg-scan
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/reg-scan
|
71
|
+
- input.text
|
72
|
+
- lib/regexp_scan.rb
|
73
|
+
- lib/regexp_scan/scanner.rb
|
74
|
+
- lib/regexp_scan/version.rb
|
75
|
+
- regexp_scan.gemspec
|
76
|
+
- test/minitest_helper.rb
|
77
|
+
- test/test_scanner.rb
|
78
|
+
homepage: https://github.com/Shinya131/regexp_scan
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Strings filter by Regexp.
|
102
|
+
test_files:
|
103
|
+
- test/minitest_helper.rb
|
104
|
+
- test/test_scanner.rb
|