Sha256: 93adf5a86c75eeb4fc3ae10753a563a55b90ce7aecf1876e5855d9ab8345ad11

Contents?: true

Size: 799 Bytes

Versions: 15

Compression:

Stored size: 799 Bytes

Contents

require "dry/inflector"

module Voom
  # Helper module for converting symbol naming to string.
  # It provides common conversions for variable naming (snake_case) and class naming (class_name)
  module Symbol
    # Maps symbols to strings
    def sym_to_str(name)
      return name if name.is_a? ::String
      name.to_s
    end

    # Converts a namespaced string or symbol to snake_case
    def snake_case(str)
      inflector.underscore(sym_to_str(str).tr('.', '_'))
    end

    # Converts a namespaced symbol or string to a proper class name with modules
    def class_name(classname)
      classname = sym_to_str(classname)
      classname.split('.').map { |m| inflector.camelize(m) }.join('::')
    end

    private
    def inflector
      @inflector ||= Dry::Inflector.new
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
voom-presenters-0.2.0 lib/voom/symbol/to_str.rb
voom-presenters-0.1.13 lib/voom/symbol/to_str.rb
voom-presenters-0.1.12 lib/voom/symbol/to_str.rb
voom-presenters-0.1.11 lib/voom/symbol/to_str.rb
voom-presenters-0.1.10 lib/voom/symbol/to_str.rb
voom-presenters-0.1.9 lib/voom/symbol/to_str.rb
voom-presenters-0.1.8 lib/voom/symbol/to_str.rb
voom-presenters-0.1.7 lib/voom/symbol/to_str.rb
voom-presenters-0.1.6 lib/voom/symbol/to_str.rb
voom-presenters-0.1.5 lib/voom/symbol/to_str.rb
voom-presenters-0.1.4 lib/voom/symbol/to_str.rb
voom-presenters-0.1.3 lib/voom/symbol/to_str.rb
voom-presenters-0.1.2 lib/voom/symbol/to_str.rb
voom-presenters-0.1.1 lib/voom/symbol/to_str.rb
voom-presenters-0.1.0 lib/voom/symbol/to_str.rb