Sha256: 6e1804b241c3cee8f9f9b4b43528c2101fdaf75993009156eee314965b86598b

Contents?: true

Size: 810 Bytes

Versions: 1

Compression:

Stored size: 810 Bytes

Contents

module Belajar
  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)
        if text
          parts = text.to_s.split(QuickStore.config.key_separator).map do |key|
            key.gsub(LEADING_NUMBERS, '').gsub(PART_JOINTS, '_').downcase
          end

          parts.join(QuickStore.config.key_separator)
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
belajar-0.1.1 lib/belajar/storeable.rb