command_search 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 217fdaec3f53844fbda942d9b8f9cb6422cfd422
4
- data.tar.gz: ffbc227be18fa8fcd947dd42889838719921cbed
3
+ metadata.gz: 0ff69a298e109d79d1cf70f7bc0d1470129d447d
4
+ data.tar.gz: 37bfc67ff6702e307087611b5e75db52ce6334c7
5
5
  SHA512:
6
- metadata.gz: ec86ff8eccc714a7ac0aae2a36f78c6a36bad5fcfb87fd61dbfbb8544b27f008f787604a3e50241c309ce8335177097e78c311487873baee09043a5d3243fa4e
7
- data.tar.gz: be520d824f7f9ef919089da78adfdde811a2e1e072b791cf5ec1fa4f462d09b538d7272e7417083992305ee4e4dbffa15a42efb3c11deadd5b7b4cfb1a796f93
6
+ metadata.gz: b53dbc26c9a8db5cd13c48b4def9065f29031fab0ed1336cefbb94f6e197ce7172db18e5b81937a4ee68d08a0ec700cd90145bf0996f1d5af32d70423b6f10ec
7
+ data.tar.gz: 5f5a24aed587abe88c7408c3855360826b7fedcc00ab7f242e161717a8858465f82196aacb5d046ed9b98b985e6e88f843aeeb97b2b47dfcb4da00038cd6b318
@@ -3,8 +3,8 @@ module CommandSearch
3
3
  module_function
4
4
 
5
5
  def build_regex(str)
6
- head_border = '(?<=^|\s|[|(-])'
7
- tail_border = '(?=$|\s|[|)])'
6
+ head_border = '(?<=^|[^:\w])'
7
+ tail_border = '(?=$|\W)'
8
8
  Regexp.new(head_border + Regexp.escape(str) + tail_border, 'i')
9
9
  end
10
10
 
@@ -26,11 +26,17 @@ module CommandSearch
26
26
  elsif !item.key?(cmd)
27
27
  return false
28
28
  elsif val[1][:type] == :str
29
- item[cmd][/#{Regexp.escape(cmd_search)}/mi]
29
+ item[cmd][/#{Regexp.escape(cmd_search)}/i]
30
30
  elsif val[1][:type] == :quoted_str
31
- item[cmd][/\b#{Regexp.escape(cmd_search)}\b/]
31
+ regex = /\b#{Regexp.escape(cmd_search)}\b/
32
+ if cmd_search.first[/\W/] || cmd_search.last[/\W/]
33
+ head_border = '(?<=^|[^:+\w])'
34
+ tail_border = '(?=$|[^:+\w])'
35
+ regex = Regexp.new(head_border + Regexp.escape(cmd_search) + tail_border)
36
+ end
37
+ item[cmd][regex]
32
38
  else
33
- item[cmd].to_s[/#{Regexp.escape(cmd_search)}/mi]
39
+ item[cmd].to_s[/#{Regexp.escape(cmd_search)}/i]
34
40
  end
35
41
  end
36
42
 
@@ -77,9 +83,15 @@ module CommandSearch
77
83
  case node[:nest_type]
78
84
  when nil
79
85
  if node[:type] == :quoted_str
80
- field_vals.any? { |x| x.to_s[/\b#{Regexp.escape(val)}\b/] }
86
+ regex = /\b#{Regexp.escape(val)}\b/
87
+ if val.first[/\W/] || val.last[/\W/]
88
+ head_border = '(?<=^|[^:+\w])'
89
+ tail_border = '(?=$|[^:+\w])'
90
+ regex = Regexp.new(head_border + Regexp.escape(val) + tail_border)
91
+ end
92
+ field_vals.any? { |x| x.to_s[regex] }
81
93
  else
82
- field_vals.any? { |x| x.to_s[/#{Regexp.escape(val)}/mi] }
94
+ field_vals.any? { |x| x.to_s[/#{Regexp.escape(val)}/i] }
83
95
  end
84
96
  when :colon
85
97
  command_check(item, val, command_types)
@@ -9,8 +9,13 @@ module CommandSearch
9
9
  fields = [fields] unless fields.is_a?(Array)
10
10
  if ast_node[:type] == :quoted_str
11
11
  regex = /\b#{Regexp.escape(str)}\b/
12
+ if str.first[/\W/] || str.last[/\W/]
13
+ head_border = '(?<=^|[^:+\w])'
14
+ tail_border = '(?=$|[^:+\w])'
15
+ regex = Regexp.new(head_border + Regexp.escape(str) + tail_border)
16
+ end
12
17
  else
13
- regex = /#{Regexp.escape(str)}/mi
18
+ regex = /#{Regexp.escape(str)}/i
14
19
  end
15
20
  if ast_node[:negate]
16
21
  forms = fields.map { |f| { f => { '$not' => regex } } }
@@ -82,8 +87,13 @@ module CommandSearch
82
87
  elsif type == String
83
88
  if search_type == :quoted_str
84
89
  val = /\b#{Regexp.escape(raw_val)}\b/
90
+ if raw_val.first[/\W/] || raw_val.last[/\W/]
91
+ head_border = '(?<=^|[^:+\w])'
92
+ tail_border = '(?=$|[^:+\w])'
93
+ val = Regexp.new(head_border + Regexp.escape(raw_val) + tail_border)
94
+ end
85
95
  else
86
- val = /#{Regexp.escape(raw_val)}/mi
96
+ val = /#{Regexp.escape(raw_val)}/i
87
97
  end
88
98
  elsif [Numeric, Integer].include?(type)
89
99
  if raw_val == raw_val.to_i.to_s
@@ -111,10 +121,6 @@ module CommandSearch
111
121
  end
112
122
  end
113
123
 
114
- # regex (case insensitive probably best default, and let
115
- # proper regex and alias support allow developers to have
116
- # case sensitive if they want maybe.)
117
-
118
124
  if field_node[:negate] && (type == Numeric || type == String)
119
125
  { key => { '$not' => val } }
120
126
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zumbalogy