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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be1d8270d9f5ea13c2c59b798840b9f3aef96202
4
- data.tar.gz: b96884005116a76932a4fcc67cfce9dc9838830b
3
+ metadata.gz: ef4b742374b34439e6b378f8d4e1e78919952cd0
4
+ data.tar.gz: 3f251199c69d2d8bac3248bc31e4a676ea7aa24f
5
5
  SHA512:
6
- metadata.gz: e9fc659ec4e460354ec8d06a4c05750d57584d38b210dbe013b38cc73c7bd98ba44e0f6f3468020240182178ffef6f140ccdff19d3ef09c99c5700c48e8e8c32
7
- data.tar.gz: 705a2ab3eaa628ca1b10fca1ab3f6f3eb53fdbbc8067f5d7d4d6f469d2a503e775c572c4026c026b2570486198a0322dea55df25f70ed7a1935e6ee51549f33a
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` accept these options
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` accept only
50
+ and `*_with_only` accepts only
51
51
 
52
52
  ```ruby
53
53
  :numbers
@@ -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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup)
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 = self.dup, other = other_str.dup, target)
43
+ remove_this_regex!(str = dup, other = other_str.dup, target)
44
44
  else
45
- remove_this!(str = self.dup, other = other_str.dup, target)
45
+ remove_this!(str = dup, other = other_str.dup, target)
46
46
  end
47
47
  str <=> other
48
48
  end
49
49
 
50
- alias_method :cmp_without_these, :cmp_without_this
50
+ alias cmp_without_these cmp_without_this
51
51
 
52
- def cmp_without_theses_words(other_str, array)
53
- remove_these_words!(str = self.dup, other = other_str.dup, array.dup)
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
- alias_method :cmp_without_regex, :cmp_without_this
60
+ alias cmp_without_regex cmp_without_this
58
61
  end
59
- end
62
+ end
@@ -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) == 0
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) == 0
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) == 0
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) == 0
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) == 0
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) == 0
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) == 0
32
+ cmp_without_this(other_str, target).zero?
34
33
  end
35
34
 
36
- alias_method :eql_without_regex?, :eql_without_this?
35
+ alias eql_without_regex? eql_without_this?
37
36
 
38
- def eql_without_these?(other_str, array)
39
- cmp_without_these(other_str, array) == 0
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
- def eql_without_these_words?(other_str, array)
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, array)
41
- array.map { |w| Regexp.escape(w) }
42
- remove_this_regex!(str, other_str, Regexp.union(array))
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
@@ -12,4 +12,4 @@ class String
12
12
  include UselessString::WithoutStarter
13
13
 
14
14
  include UselessString::WithOnlyStarter
15
- end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module UselessString
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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 = self.dup, other = other_str.dup, r = create_regex(options))
6
- options[:case_insensitive] ? str.upcase.eql?(other.upcase) : str.eql?(other)
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 = self.dup, other = other_str.dup, create_regex(options))
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
- def create_regex(options)
17
- reg = '[^'
18
- reg += '\d' if options[:numbers]
19
- reg += 'a-zA-Z' if options[:alphabets]
20
- reg += ?]
21
- Regexp.new(reg)
22
- end
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
- def remove_extras(str, other_str, regex)
25
- str.gsub!(regex, '')
26
- other_str.gsub!(regex, '')
27
- end
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
@@ -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 = self.dup, other = other_str.dup, options)
6
- options[:case_insensitive] ? str.upcase.eql?(other.upcase) : str.eql?(other)
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 = self.dup, other = other_str.dup, options)
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
- def set_according_to_options(str, other_str, options)
17
- remove_carriage_return!(str, other_str) if options[:carriage_return]
18
- remove_line_feed!(str, other_str) if options[:line_feed]
19
- remove_end_of_line!(str, other_str) if options[:end_of_line]
20
- remove_spaces!(str, other_str) if options[:spaces]
21
- remove_numbers!(str, other_str) if options[:numbers]
22
- remove_special_characters!(str, other_str) if options[:special_characters]
23
- remove_alphabets!(str, other_str) if options[:alphabets]
24
- remove_these_words!(str, other_str, options[:words]) if options[:words]
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
@@ -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 = "useless_string"
7
+ spec.name = 'useless_string'
8
8
  spec.version = UselessString::VERSION
9
- spec.authors = ["Azam", "Ali Nawazish"]
10
- spec.email = ["azam.ikram22@gmail.com", "m_ali3119@yahoo.com"]
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 = "MIT"
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 = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1.12"
33
- spec.add_development_dependency "rake", "~> 10.0"
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.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: 2016-11-17 00:00:00.000000000 Z
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.5.1
84
+ rubygems_version: 2.6.8
87
85
  signing_key:
88
86
  specification_version: 4
89
87
  summary: Advance string comparison in ruby.