Module: HasHandleFallback

Defined in:
lib/has_handle_fallback.rb

Defined Under Namespace

Modules: ActiveRecordBaseMethods, ClassMethods, InstanceMethods

Constant Summary collapse

SUB_REGEXP =
'\_\-a-zA-Z0-9'
REGEXP =
/\A[#{SUB_REGEXP}]+\z/
ANTI_REGEXP =
/[^#{SUB_REGEXP}]+/
LENGTH_RANGE =
2..32
RECORD_ID_REGEXP =
/\A\d+\z/

Class Method Summary collapse

Class Method Details

.str2handle(str) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/has_handle_fallback.rb', line 18

def self.str2handle(str)
  str = str.to_s.dup
  str.gsub! ANTI_REGEXP, ''
  str = str.underscore
  str << ('_' * (LENGTH_RANGE.min - str.length)) if str.length < LENGTH_RANGE.min
  str[0, LENGTH_RANGE.max]
end