Module: Origin::Extensions::String
- Defined in:
- lib/origin/extensions/string.rb
Overview
This module contains additional object behaviour.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__evolve_date__ ⇒ Time
Evolve the string into a mongodb friendly date.
-
#__evolve_time__ ⇒ Time
Evolve the string into a mongodb friendly time.
-
#__sort_option__ ⇒ Hash
Get the string as a sort option.
-
#specify(value, negating = false) ⇒ Hash
Get the string as a specification.
-
#to_direction ⇒ Integer
Get the string as a sort direction.
Instance Method Details
#__evolve_date__ ⇒ Time
Evolve the string into a mongodb friendly date.
16 17 18 19 |
# File 'lib/origin/extensions/string.rb', line 16 def __evolve_date__ time = ::Time.parse(self) ::Time.utc(time.year, time.month, time.day, 0, 0, 0, 0) end |
#__evolve_time__ ⇒ Time
Evolve the string into a mongodb friendly time.
29 30 31 |
# File 'lib/origin/extensions/string.rb', line 29 def __evolve_time__ ::Time.parse(self).utc end |
#__sort_option__ ⇒ Hash
Get the string as a sort option.
41 42 43 44 45 46 47 48 |
# File 'lib/origin/extensions/string.rb', line 41 def __sort_option__ split(/,/).inject({}) do |hash, spec| hash.tap do |_hash| field, direction = spec.strip.split(/\s/) _hash[field.to_sym] = direction.to_direction end end end |
#specify(value, negating = false) ⇒ Hash
Get the string as a specification.
61 62 63 |
# File 'lib/origin/extensions/string.rb', line 61 def specify(value, negating = false) (negating && value.regexp?) ? { self => { "$not" => value } } : { self => value } end |
#to_direction ⇒ Integer
Get the string as a sort direction.
73 74 75 |
# File 'lib/origin/extensions/string.rb', line 73 def to_direction self =~ /desc/i ? -1 : 1 end |