module Yarrow::Symbols
Public Class Methods
from_const(const_obj)
click to toggle source
Converts a string name of class const to a symbol atom
@param [Class, String, to_s] const_obj @return [Symbol]
# File lib/yarrow/symbols.rb, line 26 def self.from_const(const_obj) const_lookup = if const_obj.respond_to?(:name) const_obj.name else const_obj.to_s end Strings::Case.underscore(const_lookup).to_sym end
to_const(atom)
click to toggle source
Converts an atomic content identifier to a live class constant.
@param [Symbol, String] atom @return [Object]
# File lib/yarrow/symbols.rb, line 18 def self.to_const(atom) Object.const_get(Strings::Case.pascalcase(atom.to_s).to_sym) end
to_module_const(parts)
click to toggle source
@param [Array<String>, Array<Symbol>] parts @return [Object]
# File lib/yarrow/symbols.rb, line 8 def self.to_module_const(parts) Object.const_get(parts.map { |atom| Strings::Case.pascalcase(atom.to_s) }.join("::")) end
to_plural(atom)
click to toggle source
@param [Symbol, String] atom @return [Symbol]
# File lib/yarrow/symbols.rb, line 44 def self.to_plural(atom) Strings::Inflection.pluralize(atom.to_s).to_sym end
to_singular(atom)
click to toggle source
@param [Symbol, String] atom @return [Symbol]
# File lib/yarrow/symbols.rb, line 38 def self.to_singular(atom) Strings::Inflection.singularize(atom.to_s).to_sym end
to_text(identifier)
click to toggle source
@param [Symbol, String] atom @return [String]
# File lib/yarrow/symbols.rb, line 50 def self.to_text(identifier) identifier.to_s.gsub(/\A[^[:alnum:]]+/, "").gsub(/[\-_]+/, " ").capitalize end