Module: Yarrow::Symbols
- Defined in:
- lib/yarrow/symbols.rb
Class Method Summary collapse
-
.from_const(const_obj) ⇒ Symbol
Converts a string name of class const to a symbol atom.
-
.to_const(atom) ⇒ Object
Converts an atomic content identifier to a live class constant.
- .to_module_const(parts) ⇒ Object
- .to_plural(atom) ⇒ Symbol
- .to_singular(atom) ⇒ Symbol
- .to_text(identifier) ⇒ String
Class Method Details
.from_const(const_obj) ⇒ Symbol
Converts a string name of class const to a symbol atom
26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
Converts an atomic content identifier to a live class constant.
18 19 20 |
# 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) ⇒ Object
8 9 10 11 12 |
# 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) ⇒ Symbol
44 45 46 |
# File 'lib/yarrow/symbols.rb', line 44 def self.to_plural(atom) Strings::Inflection.pluralize(atom.to_s).to_sym end |
.to_singular(atom) ⇒ Symbol
38 39 40 |
# File 'lib/yarrow/symbols.rb', line 38 def self.to_singular(atom) Strings::Inflection.singularize(atom.to_s).to_sym end |
.to_text(identifier) ⇒ String
50 51 52 |
# File 'lib/yarrow/symbols.rb', line 50 def self.to_text(identifier) identifier.to_s.gsub(/\A[^[:alnum:]]+/, "").gsub(/[\-_]+/, " ").capitalize end |