Sha256: 1342cafe51f3eede995ac5fd82e80a16867509fae5f2d57bf33688b8eaffe3fc

Contents?: true

Size: 861 Bytes

Versions: 4

Compression:

Stored size: 861 Bytes

Contents

module Daigaku
  module Storeable
    LEADING_NUMBERS = /^\d+[\_\-\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]
        suffixes_items = suffixes ? suffixes.map { |s| clean(s) }.compact : nil

        [prefix, clean(text), suffix || suffixes_items].compact.join(separator)
      end

      private

      def clean(text)
        return if text.nil?
        parts(text.to_s).join(QuickStore.config.key_separator)
      end

      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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daigaku-1.0.0 lib/daigaku/storeable.rb
daigaku-0.6.0 lib/daigaku/storeable.rb
daigaku-0.5.0 lib/daigaku/storeable.rb
daigaku-0.4.0 lib/daigaku/storeable.rb