module ArelExtensions::StringFunctions

Public Instance Methods

&(other) click to toggle source

*FindInSet function .……

# File lib/arel_extensions/string_functions.rb, line 23
def &(other)
  ArelExtensions::Nodes::FindInSet.new [other, self]
end
[](start, ind = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 50
def [](start, ind = nil)
  start += 1 if start.is_a?(Integer)
  if start.is_a?(Range)
    ArelExtensions::Nodes::Substring.new [self, start.begin + 1, start.end - start.begin + 1]
  elsif start.is_a?(Integer) && !ind
    ArelExtensions::Nodes::Substring.new [self, start, 1]
  else
    ArelExtensions::Nodes::Substring.new [self, start, ind - start + 1]
  end
end
ai_collate() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 115
def ai_collate
  ArelExtensions::Nodes::Collate.new(self, nil, true, false)
end
ai_imatches(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 107
def ai_imatches other # accent insensitive & case insensitive
  ArelExtensions::Nodes::AiIMatches.new(self, other)
end
ai_matches(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 103
def ai_matches other # accent insensitive & case sensitive
  ArelExtensions::Nodes::AiMatches.new(self, other)
end
blank() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 180
def blank
  ArelExtensions::Nodes::Blank.new [self]
end
byte_length() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 32
def byte_length
  ArelExtensions::Nodes::Length.new self, true
end
char_length() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 36
def char_length
  ArelExtensions::Nodes::Length.new self, false
end
ci_collate() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 119
def ci_collate
  ArelExtensions::Nodes::Collate.new(self, nil, false, true)
end
collate(ai = false, ci = false, option = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 123
def collate ai = false, ci = false, option = nil
  ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
end
concat(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 140
def concat other
  ArelExtensions::Nodes::Concat.new [self, other]
end
downcase() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 172
def downcase
  ArelExtensions::Nodes::Downcase.new [self]
end
edit_distance(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 196
def edit_distance other
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
end
group_concat(sep = nil, *orders, group: nil, order: nil) click to toggle source

concat elements of a group, separated by sep and ordered by a list of Ascending or Descending

# File lib/arel_extensions/string_functions.rb, line 145
def group_concat(sep = nil, *orders, group: nil, order: nil)
  if orders.present?
    warn("Warning: ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
  end
  order_tabs = [orders].flatten.map{ |o|
    if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
      o
    elsif o.respond_to?(:asc)
      o.asc
    end
  }.compact
  ArelExtensions::Nodes::GroupConcat.new(self, sep, group: group, order: (order || order_tabs))
end
idoes_not_match(others, escape = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 91
def idoes_not_match others, escape = nil
  ArelExtensions::Nodes::IDoesNotMatch.new self, others, escape
end
idoes_not_match_all(others, escape = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 99
def idoes_not_match_all others, escape = nil
  grouping_all :idoes_not_match, others, escape
end
idoes_not_match_any(others, escape = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 95
def idoes_not_match_any others, escape = nil
  grouping_any :idoes_not_match, others, escape
end
imatches(others, escape = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 66
def imatches others, escape = nil
  ArelExtensions::Nodes::IMatches.new self, others, escape
end
imatches_all(others, escape = nil) click to toggle source

def grouping_any method, others, *extra

puts "*******************"
puts method
puts others.inspect
puts extra.inspect
puts "-------------------"
res = super(method,others,*extra)
puts res.to_sql
puts res.inspect
puts "*******************"
res

end

# File lib/arel_extensions/string_functions.rb, line 87
def imatches_all others, escape = nil
  grouping_all :imatches, others, escape, escape
end
imatches_any(others, escape = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 70
def imatches_any others, escape = nil
  grouping_any :imatches, others, escape
end
length() click to toggle source

LENGTH function returns the length (bytewise) of the value in a text field.

# File lib/arel_extensions/string_functions.rb, line 28
def length
  ArelExtensions::Nodes::Length.new self, true
end
levenshtein_distance(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 192
def levenshtein_distance other
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
end
locate(val) click to toggle source

LOCATE function returns the first starting position of a string in another string. If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.

# File lib/arel_extensions/string_functions.rb, line 42
def locate val
  ArelExtensions::Nodes::Locate.new [self, val]
end
ltrim(other = ' ') click to toggle source
# File lib/arel_extensions/string_functions.rb, line 164
def ltrim other = ' '
  ArelExtensions::Nodes::Ltrim.new [self, other]
end
md5() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 200
def md5
  ArelExtensions::Nodes::MD5.new [self]
end
not_blank() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 184
def not_blank
  ArelExtensions::Nodes::NotBlank.new [self]
end
regexp_replace(pattern, substitute) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 136
def regexp_replace pattern, substitute
  ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
end
repeat(other = 1) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 188
def repeat other = 1
  ArelExtensions::Nodes::Repeat.new [self, other]
end
replace(pattern, substitute) click to toggle source

REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.

# File lib/arel_extensions/string_functions.rb, line 128
def replace pattern, substitute
  if pattern.is_a? Regexp
    ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
  else
    ArelExtensions::Nodes::Replace.new self, pattern, substitute
  end
end
rtrim(other = ' ') click to toggle source
# File lib/arel_extensions/string_functions.rb, line 168
def rtrim other = ' '
  ArelExtensions::Nodes::Rtrim.new [self, other]
end
smatches(other) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 111
def smatches other # accent sensitive & case sensitive
  ArelExtensions::Nodes::SMatches.new(self, other)
end
soundex() click to toggle source

SOUNDEX function returns a character string containing the phonetic representation of char.

# File lib/arel_extensions/string_functions.rb, line 62
def soundex
  ArelExtensions::Nodes::Soundex.new [self]
end
substring(start, len = nil) click to toggle source
# File lib/arel_extensions/string_functions.rb, line 46
def substring start, len = nil
  ArelExtensions::Nodes::Substring.new [self, start, len]
end
trim(other = ' ') click to toggle source

Function returns a string after removing left, right or the both prefixes or suffixes int argument

# File lib/arel_extensions/string_functions.rb, line 160
def trim other = ' '
  ArelExtensions::Nodes::Trim.new [self, other]
end
upcase() click to toggle source
# File lib/arel_extensions/string_functions.rb, line 176
def upcase
  ArelExtensions::Nodes::Upcase.new [self]
end