Sha256: a2b26bc542188d51731b96def845078380a557b2226138843e585cd146b8a473

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module LesliBabel
    class Module < ApplicationRecord
        has_many :buckets

        validates_presence_of :platform

        before_create :format_module_name

        def self.index 
            Module.where("name is not null")
            order(id: :desc).map do |translation_module|
                {
                    id: translation_module[:id],
                    name: translation_module[:name],
                    code: translation_module[:name].downcase,
                    platform: translation_module[:platform]
                }
            end
        end

        def format_module_name

            return if self.platform == "lesli_core"
            return if self.platform == "lesli_engine"

            self.name = self.name
            .gsub(/[^0-9A-Za-z\s\-\_]/, '')  # remove special characters from string
            .gsub(/-/, '')                   # replace dashes with underscore
            .gsub(/_/, '')                   # replace underscore with underscore
            .titlecase                       # Capitalizes all the words
            .gsub(/\s+/, '')                 # remove blank spaces
        end 

    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lesli_babel-0.2.0 app/models/lesli_babel/module.rb
lesli_babel-0.1.0 app/models/lesli_babel/module.rb