Class: MongoidPermalinkExtension::Permalink

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_permalink_extension/permalink.rb

Class Method Summary collapse

Class Method Details

.demongoize(value) ⇒ Object


8
9
10
# File 'lib/mongoid_permalink_extension/permalink.rb', line 8

def demongoize(value)
  value
end

.mongoize(value) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mongoid_permalink_extension/permalink.rb', line 12

def mongoize(value)
  return if value.nil? # FIXME: this way we can never set the value to nil
  value.to_s
       .gsub(/\A\s+|\s+\z/, '')
       .gsub(/([^[:upper:]](?=[[:upper:]]))|([a-z](?=\d+))/, '\1\2-')
       .gsub(/\//, '-')
       .gsub(/[-–—]+/, '-')
       .gsub(/[^\p{Alnum} -]/, '')
       .gsub(/\s+/, '-')
       .gsub(/[-]+/, '-')
       .gsub(/\A\-/, '')
       .gsub(/\b\w/) { $&.upcase }
       .to_ascii
end