Module: ArelExtensions::StringFunctions

Included in:
Attributes
Defined in:
lib/arel_extensions/string_functions.rb

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

*FindInSet function .……



24
25
26
# File 'lib/arel_extensions/string_functions.rb', line 24

def &(other)
  ArelExtensions::Nodes::FindInSet.new [other, self]
end

#[](start, ind = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/arel_extensions/string_functions.rb', line 43

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_collateObject



95
96
97
# File 'lib/arel_extensions/string_functions.rb', line 95

def ai_collate
  ArelExtensions::Nodes::Collate.new(self,nil,true,false)
end

#ai_imatches(other) ⇒ Object

accent insensitive & case insensitive



87
88
89
# File 'lib/arel_extensions/string_functions.rb', line 87

def ai_imatches other # accent insensitive & case insensitive
  ArelExtensions::Nodes::AiIMatches.new(self,other)
end

#ai_matches(other) ⇒ Object

accent insensitive & case sensitive



83
84
85
# File 'lib/arel_extensions/string_functions.rb', line 83

def ai_matches other # accent insensitive & case sensitive
  ArelExtensions::Nodes::AiMatches.new(self,other)
end

#blankObject



154
155
156
# File 'lib/arel_extensions/string_functions.rb', line 154

def blank
  ArelExtensions::Nodes::Blank.new [self]
end

#ci_collateObject



99
100
101
# File 'lib/arel_extensions/string_functions.rb', line 99

def ci_collate
  ArelExtensions::Nodes::Collate.new(self,nil,false,true)
end

#collate(ai = false, ci = false, option = nil) ⇒ Object



103
104
105
# File 'lib/arel_extensions/string_functions.rb', line 103

def collate ai=false,ci=false, option=nil
  ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
end

#concat(other) ⇒ Object



112
113
114
# File 'lib/arel_extensions/string_functions.rb', line 112

def concat other
  ArelExtensions::Nodes::Concat.new [self, other]
end

#downcaseObject



146
147
148
# File 'lib/arel_extensions/string_functions.rb', line 146

def downcase
  ArelExtensions::Nodes::Downcase.new [self]
end

#edit_distance(other) ⇒ Object



170
171
172
# File 'lib/arel_extensions/string_functions.rb', line 170

def edit_distance other
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
end

#group_concat(sep = nil, *orders, group: nil, order: nil) ⇒ Object

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/arel_extensions/string_functions.rb', line 117

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
    else
      nil
    end
  }.compact
  ArelExtensions::Nodes::GroupConcat.new(self, sep, group: group, order: (order || order_tabs))
end

#idoes_not_match(others, escape = nil) ⇒ Object



71
72
73
# File 'lib/arel_extensions/string_functions.rb', line 71

def idoes_not_match others, escape = nil
  ArelExtensions::Nodes::IDoesNotMatch.new self, others, escape
end

#idoes_not_match_all(others, escape = nil) ⇒ Object



79
80
81
# File 'lib/arel_extensions/string_functions.rb', line 79

def idoes_not_match_all others, escape = nil
  grouping_all :idoes_not_match, others, escape
end

#idoes_not_match_any(others, escape = nil) ⇒ Object



75
76
77
# File 'lib/arel_extensions/string_functions.rb', line 75

def idoes_not_match_any others, escape = nil
  grouping_any :idoes_not_match, others, escape
end

#imatches(others, escape = nil) ⇒ Object



59
60
61
# File 'lib/arel_extensions/string_functions.rb', line 59

def imatches others, escape = nil
  ArelExtensions::Nodes::IMatches.new self, others, escape
end

#imatches_all(others, escape = nil) ⇒ Object



67
68
69
# File 'lib/arel_extensions/string_functions.rb', line 67

def imatches_all others, escape = nil
  grouping_all :imatches, others, escape, escape
end

#imatches_any(others, escape = nil) ⇒ Object



63
64
65
# File 'lib/arel_extensions/string_functions.rb', line 63

def imatches_any others, escape = nil
  grouping_any :imatches, others, escape
end

#lengthObject

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



29
30
31
# File 'lib/arel_extensions/string_functions.rb', line 29

def length
  ArelExtensions::Nodes::Length.new [self]
end

#levenshtein_distance(other) ⇒ Object



166
167
168
# File 'lib/arel_extensions/string_functions.rb', line 166

def levenshtein_distance other
  ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
end

#locate(val) ⇒ Object

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.



35
36
37
# File 'lib/arel_extensions/string_functions.rb', line 35

def locate val
  ArelExtensions::Nodes::Locate.new [self, val]
end

#ltrim(other = ' ') ⇒ Object



138
139
140
# File 'lib/arel_extensions/string_functions.rb', line 138

def ltrim other = ' '
  ArelExtensions::Nodes::Ltrim.new [self, other]
end

#md5Object



174
175
176
# File 'lib/arel_extensions/string_functions.rb', line 174

def md5
  ArelExtensions::Nodes::MD5.new [self]
end

#not_blankObject



158
159
160
# File 'lib/arel_extensions/string_functions.rb', line 158

def not_blank
  ArelExtensions::Nodes::NotBlank.new [self]
end

#repeat(other = 1) ⇒ Object



162
163
164
# File 'lib/arel_extensions/string_functions.rb', line 162

def repeat other = 1
  ArelExtensions::Nodes::Repeat.new [self, other]
end

#replace(left, right) ⇒ Object

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



108
109
110
# File 'lib/arel_extensions/string_functions.rb', line 108

def replace left, right
  ArelExtensions::Nodes::Replace.new [self, left, right]
end

#rtrim(other = ' ') ⇒ Object



142
143
144
# File 'lib/arel_extensions/string_functions.rb', line 142

def rtrim other = ' '
  ArelExtensions::Nodes::Rtrim.new [self, other]
end

#smatches(other) ⇒ Object

accent sensitive & case sensitive



91
92
93
# File 'lib/arel_extensions/string_functions.rb', line 91

def smatches other # accent sensitive & case sensitive
  ArelExtensions::Nodes::SMatches.new(self,other)
end

#soundexObject

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



55
56
57
# File 'lib/arel_extensions/string_functions.rb', line 55

def soundex
  ArelExtensions::Nodes::Soundex.new [self]
end

#substring(start, len = nil) ⇒ Object



39
40
41
# File 'lib/arel_extensions/string_functions.rb', line 39

def substring start, len = nil
  ArelExtensions::Nodes::Substring.new [self, start, len]
end

#trim(other = ' ') ⇒ Object

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



134
135
136
# File 'lib/arel_extensions/string_functions.rb', line 134

def trim other = ' '
  ArelExtensions::Nodes::Trim.new [self, other]
end

#upcaseObject



150
151
152
# File 'lib/arel_extensions/string_functions.rb', line 150

def upcase
  ArelExtensions::Nodes::Upcase.new [self]
end