useless_string 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +3 -3
- data/lib/compare_without.rb +17 -14
- data/lib/equal_without.rb +12 -15
- data/lib/helpers/without_helper.rb +7 -4
- data/lib/useless_string.rb +1 -1
- data/lib/useless_string/version.rb +1 -1
- data/lib/with_only_starter.rb +15 -16
- data/lib/without_starter.rb +18 -14
- data/useless_string.gemspec +9 -9
- metadata +3 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef4b742374b34439e6b378f8d4e1e78919952cd0
|
4
|
+
data.tar.gz: 3f251199c69d2d8bac3248bc31e4a676ea7aa24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523ce57587e14da3bbe968d98d2b910fdf5fbcba7ebe4234294f33997fddd88edc66fa704a703bb86edf7db3db89aa99258b141fa038c057acb3ecd190a5c269
|
7
|
+
data.tar.gz: a4640fbf2a224258a5c42182689b2ef1fa908197561cca6f766a54fba1f66db765ec4a58419dbe16b182199e4cabcb12f69868f633e66a74333ccd19504338ad
|
data/README.md
CHANGED
@@ -34,8 +34,8 @@ $ first.eql_with_only?(second, numbers: true)
|
|
34
34
|
```
|
35
35
|
|
36
36
|
There is also a method `eql_without?` which will take a string and an options hash. You can use
|
37
|
-
`eql_*` or `cmp_*`. For now `*_without`
|
38
|
-
|
37
|
+
`eql_*` or `cmp_*`. For now `*_without` accepts these options
|
38
|
+
|
39
39
|
```ruby
|
40
40
|
:carriage_return
|
41
41
|
:line_feed
|
@@ -47,7 +47,7 @@ There is also a method `eql_without?` which will take a string and an options ha
|
|
47
47
|
:case_insensitive
|
48
48
|
:words # takes an array of words
|
49
49
|
```
|
50
|
-
and `*_with_only`
|
50
|
+
and `*_with_only` accepts only
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
:numbers
|
data/lib/compare_without.rb
CHANGED
@@ -4,56 +4,59 @@ module UselessString
|
|
4
4
|
include UselessString::WithoutHelper
|
5
5
|
|
6
6
|
def cmp_without_carriage_return(other_str)
|
7
|
-
remove_carriage_return!(str =
|
7
|
+
remove_carriage_return!(str = dup, other = other_str.dup)
|
8
8
|
str <=> other
|
9
9
|
end
|
10
10
|
|
11
11
|
def cmp_without_line_feed(other_str)
|
12
|
-
remove_line_feed!(str =
|
12
|
+
remove_line_feed!(str = dup, other = other_str.dup)
|
13
13
|
str <=> other
|
14
14
|
end
|
15
15
|
|
16
16
|
def cmp_without_end_of_line(other_str)
|
17
|
-
remove_end_of_line!(str =
|
17
|
+
remove_end_of_line!(str = dup, other = other_str.dup)
|
18
18
|
str <=> other
|
19
19
|
end
|
20
20
|
|
21
21
|
def cmp_without_spaces(other_str)
|
22
|
-
remove_spaces!(str =
|
22
|
+
remove_spaces!(str = dup, other = other_str.dup)
|
23
23
|
str <=> other
|
24
24
|
end
|
25
25
|
|
26
26
|
def cmp_without_numbers(other_str)
|
27
|
-
remove_numbers!(str =
|
27
|
+
remove_numbers!(str = dup, other = other_str.dup)
|
28
28
|
str <=> other
|
29
29
|
end
|
30
30
|
|
31
31
|
def cmp_without_special_characters(other_str)
|
32
|
-
remove_special_characters!(str =
|
32
|
+
remove_special_characters!(str = dup, other = other_str.dup)
|
33
33
|
str <=> other
|
34
34
|
end
|
35
35
|
|
36
36
|
def cmp_without_alphabets(other_str)
|
37
|
-
remove_alphabets!(str =
|
37
|
+
remove_alphabets!(str = dup, other = other_str.dup)
|
38
38
|
str <=> other
|
39
39
|
end
|
40
40
|
|
41
41
|
def cmp_without_this(other_str, target)
|
42
42
|
if target.is_a? Regexp
|
43
|
-
remove_this_regex!(str =
|
43
|
+
remove_this_regex!(str = dup, other = other_str.dup, target)
|
44
44
|
else
|
45
|
-
remove_this!(str =
|
45
|
+
remove_this!(str = dup, other = other_str.dup, target)
|
46
46
|
end
|
47
47
|
str <=> other
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
alias cmp_without_these cmp_without_this
|
51
51
|
|
52
|
-
def cmp_without_theses_words(other_str,
|
53
|
-
remove_these_words!(str =
|
52
|
+
def cmp_without_theses_words(other_str, target_list, case_insensitive: true)
|
53
|
+
remove_these_words!(str = dup,
|
54
|
+
other = other_str.dup,
|
55
|
+
target_list.dup,
|
56
|
+
case_insensitive)
|
54
57
|
str <=> other
|
55
58
|
end
|
56
59
|
|
57
|
-
|
60
|
+
alias cmp_without_regex cmp_without_this
|
58
61
|
end
|
59
|
-
end
|
62
|
+
end
|
data/lib/equal_without.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
module UselessString
|
2
2
|
module EqualWithout
|
3
|
-
|
4
3
|
def eql_without_carriage_return?(other_str)
|
5
|
-
cmp_without_carriage_return(other_str)
|
4
|
+
cmp_without_carriage_return(other_str).zero?
|
6
5
|
end
|
7
6
|
|
8
7
|
def eql_without_line_feed?(other_str)
|
9
|
-
cmp_without_line_feed(other_str)
|
8
|
+
cmp_without_line_feed(other_str).zero?
|
10
9
|
end
|
11
10
|
|
12
11
|
def eql_without_end_of_line?(other_str)
|
13
|
-
cmp_without_end_of_line(other_str)
|
12
|
+
cmp_without_end_of_line(other_str).zero?
|
14
13
|
end
|
15
14
|
|
16
15
|
def eql_without_spaces?(other_str)
|
17
|
-
cmp_without_spaces(other_str)
|
16
|
+
cmp_without_spaces(other_str).zero?
|
18
17
|
end
|
19
18
|
|
20
19
|
def eql_without_numbers?(other_str)
|
21
|
-
cmp_without_numbers(other_str)
|
20
|
+
cmp_without_numbers(other_str).zero?
|
22
21
|
end
|
23
22
|
|
24
23
|
def eql_without_special_characters?(other_str)
|
25
|
-
cmp_without_special_characters(other_str)
|
24
|
+
cmp_without_special_characters(other_str).zero?
|
26
25
|
end
|
27
26
|
|
28
27
|
def eql_without_alphabets?(other_str)
|
@@ -30,17 +29,15 @@ module UselessString
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def eql_without_this?(other_str, target)
|
33
|
-
cmp_without_this(other_str, target)
|
32
|
+
cmp_without_this(other_str, target).zero?
|
34
33
|
end
|
35
34
|
|
36
|
-
|
35
|
+
alias eql_without_regex? eql_without_this?
|
37
36
|
|
38
|
-
def
|
39
|
-
|
37
|
+
def eql_without_these_words?(other_str, target_list, case_insensitive: true)
|
38
|
+
cmp_without_theses_words(other_str, target_list, case_insensitive).zero?
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
|
-
cmp_without_theses_words(other_str, array) == 0
|
44
|
-
end
|
41
|
+
alias eql_without_these? eql_without_these_words?
|
45
42
|
end
|
46
|
-
end
|
43
|
+
end
|
@@ -37,9 +37,12 @@ module UselessString
|
|
37
37
|
other_str.gsub!(regex, '')
|
38
38
|
end
|
39
39
|
|
40
|
-
def remove_these_words!(str, other_str,
|
41
|
-
|
42
|
-
remove_this_regex!(str,
|
40
|
+
def remove_these_words!(str, other_str, target_list, case_insensitive: true)
|
41
|
+
target_list.map { |w| Regexp.escape(w.to_str) }
|
42
|
+
remove_this_regex!(str,
|
43
|
+
other_str,
|
44
|
+
Regexp.new(Regexp.union(target_list).source,
|
45
|
+
case_insensitive))
|
43
46
|
end
|
44
47
|
end
|
45
|
-
end
|
48
|
+
end
|
data/lib/useless_string.rb
CHANGED
data/lib/with_only_starter.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
module UselessString
|
2
2
|
module WithOnlyStarter
|
3
|
-
|
4
3
|
def eql_with_only?(other_str, options = {})
|
5
|
-
remove_extras(str =
|
6
|
-
options[:case_insensitive] ? str.
|
4
|
+
remove_extras(str = dup, other = other_str.dup, create_regex(options))
|
5
|
+
options[:case_insensitive] ? str.casecmp(other.upcase).zero? : str.eql?(other)
|
7
6
|
end
|
8
7
|
|
9
8
|
def cmp_with_only(other_str, options = {})
|
10
|
-
remove_extras(str =
|
9
|
+
remove_extras(str = dup, other = other_str.dup, create_regex(options))
|
11
10
|
options[:case_insensitive] ? str.casecmp(other) : str <=> other
|
12
11
|
end
|
13
12
|
|
14
13
|
private
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def create_regex(options)
|
16
|
+
reg = '[^'
|
17
|
+
reg += '\d' if options[:numbers]
|
18
|
+
reg += 'a-zA-Z' if options[:alphabets]
|
19
|
+
reg += ']'
|
20
|
+
Regexp.new(reg)
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def remove_extras(str, other_str, regex)
|
24
|
+
str.gsub!(regex, '')
|
25
|
+
other_str.gsub!(regex, '')
|
26
|
+
end
|
28
27
|
end
|
29
|
-
end
|
28
|
+
end
|
data/lib/without_starter.rb
CHANGED
@@ -1,27 +1,31 @@
|
|
1
1
|
module UselessString
|
2
2
|
module WithoutStarter
|
3
|
-
|
4
3
|
def eql_without?(other_str, options = {})
|
5
|
-
set_according_to_options(str =
|
6
|
-
options[:case_insensitive] ? str.
|
4
|
+
set_according_to_options(str = dup, other = other_str.dup, options)
|
5
|
+
options[:case_insensitive] ? str.casecmp(other.upcase).zero? : str.eql?(other)
|
7
6
|
end
|
8
7
|
|
9
8
|
def cmp_without(other_str, options = {})
|
10
|
-
set_according_to_options(str =
|
9
|
+
set_according_to_options(str = dup, other = other_str.dup, options)
|
11
10
|
options[:case_insensitive] ? str.casecmp(other) : str <=> other
|
12
11
|
end
|
13
12
|
|
14
13
|
private
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
def set_according_to_options(str, other_str, options)
|
16
|
+
remove_carriage_return!(str, other_str) if options[:carriage_return]
|
17
|
+
remove_line_feed!(str, other_str) if options[:line_feed]
|
18
|
+
remove_end_of_line!(str, other_str) if options[:end_of_line]
|
19
|
+
remove_spaces!(str, other_str) if options[:spaces]
|
20
|
+
remove_numbers!(str, other_str) if options[:numbers]
|
21
|
+
remove_special_characters!(str, other_str) if options[:special_characters]
|
22
|
+
remove_alphabets!(str, other_str) if options[:alphabets]
|
23
|
+
if options[:words]
|
24
|
+
remove_these_words!(str,
|
25
|
+
other_str,
|
26
|
+
options[:words],
|
27
|
+
case_insensitive: options[:case_insensitive])
|
25
28
|
end
|
29
|
+
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
data/useless_string.gemspec
CHANGED
@@ -4,16 +4,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'useless_string/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'useless_string'
|
8
8
|
spec.version = UselessString::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Azam']
|
10
|
+
spec.email = ['azam.ikram22@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = %q{Advance string comparison in ruby.}
|
13
13
|
# TODO add proper description.
|
14
14
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
15
15
|
spec.homepage = 'https://github.com/azam-noob/useless_string'
|
16
|
-
spec.license =
|
16
|
+
spec.license = 'MIT'
|
17
17
|
|
18
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -25,10 +25,10 @@ Gem::Specification.new do |spec|
|
|
25
25
|
# end
|
26
26
|
|
27
27
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
-
spec.bindir =
|
28
|
+
spec.bindir = 'exe'
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
end
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: useless_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Azam
|
8
|
-
- Ali Nawazish
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
@@ -42,7 +41,6 @@ dependencies:
|
|
42
41
|
description:
|
43
42
|
email:
|
44
43
|
- azam.ikram22@gmail.com
|
45
|
-
- m_ali3119@yahoo.com
|
46
44
|
executables: []
|
47
45
|
extensions: []
|
48
46
|
extra_rdoc_files: []
|
@@ -83,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
81
|
version: '0'
|
84
82
|
requirements: []
|
85
83
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.6.8
|
87
85
|
signing_key:
|
88
86
|
specification_version: 4
|
89
87
|
summary: Advance string comparison in ruby.
|