lib/belajar/storeable.rb in belajar-0.1.1 vs lib/belajar/storeable.rb in belajar-1.0.0
- old
+ new
@@ -1,32 +1,31 @@
module Belajar
module Storeable
-
LEADING_NUMBERS = /^\d+[\_\-\s]+/
- PART_JOINTS = /[\_\-\s]+/
+ PART_JOINTS = /[\_\-\s]+/
class << self
def key(text, options = {})
- separator = QuickStore.config.key_separator
- prefix = options[:prefix]
- suffix = clean(options[:suffix])
- suffixes = options[:suffixes]
+ separator = QuickStore.config.key_separator
+ prefix = options[:prefix]
+ suffix = clean(options[:suffix])
+ suffixes = options[:suffixes]
suffixes_items = suffixes ? suffixes.map { |s| clean(s) }.compact : nil
[prefix, clean(text), suffix || suffixes_items].compact.join(separator)
end
private
def clean(text)
- if text
- parts = text.to_s.split(QuickStore.config.key_separator).map do |key|
- key.gsub(LEADING_NUMBERS, '').gsub(PART_JOINTS, '_').downcase
- end
+ return if text.nil?
+ parts(text.to_s).join(QuickStore.config.key_separator)
+ end
- parts.join(QuickStore.config.key_separator)
+ def parts(text)
+ text.split(QuickStore.config.key_separator).map do |key|
+ key.gsub(LEADING_NUMBERS, '').gsub(PART_JOINTS, '_').downcase
end
end
end
-
end
end