Module: Voom::Symbol::ToStr

Included in:
ContainerMethods
Defined in:
lib/voom/symbol/to_str.rb

Overview

Helper module for converting symbol naming to string. It provides common conversions for variable naming (snake_case) and class naming (class_name)

Instance Method Summary collapse

Instance Method Details

#class_name(classname) ⇒ Object

Converts a namespaced symbol or string to a proper class name with modules



19
20
21
22
# File 'lib/voom/symbol/to_str.rb', line 19

def class_name(classname)
  classname = sym_to_str(classname)
  classname.split('.').map { |m| inflector.camelize(m) }.join('::')
end

#snake_case(str) ⇒ Object

Converts a namespaced string or symbol to snake_case



14
15
16
# File 'lib/voom/symbol/to_str.rb', line 14

def snake_case(str)
  inflector.underscore(sym_to_str(str).tr('.', '_'))
end

#sym_to_str(name) ⇒ Object

Maps symbols to strings



8
9
10
11
# File 'lib/voom/symbol/to_str.rb', line 8

def sym_to_str(name)
  return name if name.is_a? ::String
  name.to_s
end