Class: String
- Defined in:
- lib/sequel_core/core_ext.rb,
lib/sequel_core/core_sql.rb
Direct Known Subclasses
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.datetime_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::CastMethods
#cast, #cast_numeric, #cast_string
Methods included from Sequel::SQL::AliasMethods
Instance Method Details
#blank? ⇒ Boolean
Strings are blank if they are empty or include only whitespace
150 151 152 |
# File 'lib/sequel_core/core_ext.rb', line 150 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)"
126 127 128 |
# File 'lib/sequel_core/core_sql.rb', line 126 def lit Sequel::LiteralString.new(self) end |
#split_sql ⇒ Object
Splits a string into separate SQL statements, removing comments and excessive white-space.
133 134 135 |
# File 'lib/sequel_core/core_sql.rb', line 133 def split_sql to_sql.split(';').map {|s| s.strip} end |
#to_date ⇒ Object
Converts a string into a Date object.
155 156 157 158 159 160 161 |
# File 'lib/sequel_core/core_ext.rb', line 155 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.
164 165 166 167 168 169 170 |
# File 'lib/sequel_core/core_ext.rb', line 164 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.datetime_class
174 175 176 177 178 179 180 |
# File 'lib/sequel_core/core_ext.rb', line 174 def to_sequel_time begin Sequel.datetime_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.
139 140 141 |
# File 'lib/sequel_core/core_sql.rb', line 139 def to_sql split("\n").to_sql end |
#to_time ⇒ Object
Converts a string into a Time object.
183 184 185 186 187 188 189 |
# File 'lib/sequel_core/core_ext.rb', line 183 def to_time begin Time.parse(self) rescue => e raise Sequel::Error::InvalidValue, "Invalid time value '#{self}' (#{e.})" end end |