Module: RedAmber::VectorStringFunction
- Included in:
- Vector
- Defined in:
- lib/red_amber/vector_string_function.rb
Overview
Mix-in for class Vector
Methods for string-like related function
Instance Method Summary collapse
-
#count_substring(pattern, ignore_case: nil) ⇒ Object
For each string in self, count occuerences of substring in given pattern.
-
#end_with(string, ignore_case: nil) ⇒ Vector
(also: #end_with?)
Check if elements in self end with a literal pattern.
-
#find_substring(pattern, ignore_case: nil) ⇒ Object
Find first occurrence of substring in string Vector.
-
#match_like(string, ignore_case: nil) ⇒ Vector
(also: #match_like?)
Match elements of self against SQL-style LIKE pattern.
-
#match_substring(pattern, ignore_case: nil) ⇒ Object
(also: #match_substring?)
For each string in self, emit true if it contains a given pattern.
-
#start_with(string, ignore_case: nil) ⇒ Vector
(also: #start_with?)
Check if elements in self start with a literal pattern.
Instance Method Details
#count_substring(string, ignore_case: nil) ⇒ Vector #count_substring(regexp, ignore_case: nil) ⇒ Vector
For each string in self, count occuerences of substring in given pattern.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/red_amber/vector_string_function.rb', line 195 def count_substring(pattern, ignore_case: nil) = Arrow::MatchSubstringOptions.new datum = case pattern when String .ignore_case = (ignore_case || false) .pattern = pattern find(:count_substring).execute([data], ) when Regexp .ignore_case = (pattern.casefold? || ignore_case || false) .pattern = pattern.source find(:count_substring_regex).execute([data], ) else = "pattern must be either String or Regexp: #{pattern.inspect}" raise VectorArgumentError, end Vector.create(datum.value) end |
#end_with(string, ignore_case: nil) ⇒ Vector Also known as: end_with?
Check if elements in self end with a literal pattern.
89 90 91 92 93 94 95 |
# File 'lib/red_amber/vector_string_function.rb', line 89 def end_with(string, ignore_case: nil) = Arrow::MatchSubstringOptions.new .ignore_case = (ignore_case || false) .pattern = string datum = find(:ends_with).execute([data], ) Vector.create(datum.value) end |
#find_substring(string, ignore_case: nil) ⇒ Vector #find_substring(regexp, ignore_case: nil) ⇒ Vector
Find first occurrence of substring in string Vector.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/red_amber/vector_string_function.rb', line 259 def find_substring(pattern, ignore_case: nil) = Arrow::MatchSubstringOptions.new datum = case pattern when String .ignore_case = (ignore_case || false) .pattern = pattern find(:find_substring).execute([data], ) when Regexp .ignore_case = (pattern.casefold? || ignore_case || false) .pattern = pattern.source find(:find_substring_regex).execute([data], ) else = "pattern must be either String or Regexp: #{pattern.inspect}" raise VectorArgumentError, end Vector.create(datum.value) end |
#match_like(string, ignore_case: nil) ⇒ Vector Also known as: match_like?
Match elements of self against SQL-style LIKE pattern.
The pattern matches a given pattern at any position.
'%' will match any number of characters,
'_' will match exactly one character,
and any other character matches itself.
To match a literal '%', '_', or '\', precede the character with a backslash.
144 145 146 147 148 149 150 |
# File 'lib/red_amber/vector_string_function.rb', line 144 def match_like(string, ignore_case: nil) = Arrow::MatchSubstringOptions.new .ignore_case = (ignore_case || false) .pattern = string datum = find(:match_like).execute([data], ) Vector.create(datum.value) end |
#match_substring(string, ignore_case: nil) ⇒ Vector #match_substring(regexp, ignore_case: nil) ⇒ Vector Also known as: match_substring?
For each string in self, emit true if it contains a given pattern.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/red_amber/vector_string_function.rb', line 51 def match_substring(pattern, ignore_case: nil) = Arrow::MatchSubstringOptions.new datum = case pattern when String .ignore_case = (ignore_case || false) .pattern = pattern find(:match_substring).execute([data], ) when Regexp .ignore_case = (pattern.casefold? || ignore_case || false) .pattern = pattern.source find(:match_substring_regex).execute([data], ) else = "pattern must be either String or Regexp: #{pattern.inspect}" raise VectorArgumentError, end Vector.create(datum.value) end |
#start_with(string, ignore_case: nil) ⇒ Vector Also known as: start_with?
Check if elements in self start with a literal pattern.
115 116 117 118 119 120 121 |
# File 'lib/red_amber/vector_string_function.rb', line 115 def start_with(string, ignore_case: nil) = Arrow::MatchSubstringOptions.new .ignore_case = (ignore_case || false) .pattern = string datum = find(:starts_with).execute([data], ) Vector.create(datum.value) end |