Class: String
- Includes:
- Sequel::SQL::ColumnMethods
- Defined in:
- lib/sequel_core/core_ext.rb,
lib/sequel_core/core_sql.rb
Direct Known Subclasses
Constant Summary
Constants included from Sequel::SQL::ColumnMethods
Sequel::SQL::ColumnMethods::AS, Sequel::SQL::ColumnMethods::ASC, Sequel::SQL::ColumnMethods::DESC
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Strings are blank if they are empty or include only whitespace.
-
#lit ⇒ Object
(also: #expr)
Converts a string into an LiteralString, in order to override string literalization, e.g.:.
-
#split_sql ⇒ Object
Splits a string into separate SQL statements, removing comments and excessive white-space.
-
#to_date ⇒ Object
Converts a string into a Date object.
-
#to_datetime ⇒ Object
Converts a string into a DateTime object.
-
#to_sequel_time ⇒ Object
Converts a string into a Time or DateTime object, depending on the value of Sequel.time_class.
-
#to_sql ⇒ Object
Converts a string into an SQL string by removing comments.
-
#to_time ⇒ Object
Converts a string into a Time object.
Methods included from Sequel::SQL::ColumnMethods
Instance Method Details
#blank? ⇒ Boolean
Strings are blank if they are empty or include only whitespace
164 165 166 |
# File 'lib/sequel_core/core_ext.rb', line 164 def blank? strip.empty? end |
#lit ⇒ Object Also known as: expr
Converts a string into an LiteralString, in order to override string literalization, e.g.:
DB[:items].filter(:abc => 'def').sql #=>
"SELECT * FROM items WHERE (abc = 'def')"
DB[:items].filter(:abc => 'def'.lit).sql #=>
"SELECT * FROM items WHERE (abc = def)"
115 116 117 |
# File 'lib/sequel_core/core_sql.rb', line 115 def lit Sequel::LiteralString.new(self) end |
#split_sql ⇒ Object
Splits a string into separate SQL statements, removing comments and excessive white-space.
122 123 124 |
# File 'lib/sequel_core/core_sql.rb', line 122 def split_sql to_sql.split(';').map {|s| s.strip} end |
#to_date ⇒ Object
Converts a string into a Date object.
169 170 171 172 173 174 175 |
# File 'lib/sequel_core/core_ext.rb', line 169 def to_date begin Date.parse(self) rescue => e raise Sequel::Error::InvalidValue, "Invalid date value '#{self}' (#{e.})" end end |
#to_datetime ⇒ Object
Converts a string into a DateTime object.
178 179 180 181 182 183 184 |
# File 'lib/sequel_core/core_ext.rb', line 178 def to_datetime begin DateTime.parse(self) rescue => e raise Sequel::Error::InvalidValue, "Invalid date value '#{self}' (#{e.})" end end |
#to_sequel_time ⇒ Object
Converts a string into a Time or DateTime object, depending on the value of Sequel.time_class
188 189 190 191 192 193 194 |
# File 'lib/sequel_core/core_ext.rb', line 188 def to_sequel_time begin Sequel.time_class.parse(self) rescue => e raise Sequel::Error::InvalidValue, "Invalid time value '#{self}' (#{e.})" end end |
#to_sql ⇒ Object
Converts a string into an SQL string by removing comments. See also Array#to_sql.
128 129 130 |
# File 'lib/sequel_core/core_sql.rb', line 128 def to_sql split("\n").to_sql end |
#to_time ⇒ Object
Converts a string into a Time object.
197 198 199 200 201 202 203 |
# File 'lib/sequel_core/core_ext.rb', line 197 def to_time begin Time.parse(self) rescue => e raise Sequel::Error::InvalidValue, "Invalid time value '#{self}' (#{e.})" end end |