module TTY::Option::Inflection
Public Class Methods
dasherize(name)
click to toggle source
Convert class name to dashed case
@example
dasherize("ErrorAggregator") # => "error-aggregator"
@api public
# File lib/tty/option/inflection.rb, line 44 def dasherize(name) underscore(name).tr("_", "-") end
demodulize(name)
click to toggle source
Remove all modules/class names
@example
demodulize("TTY::Option::ErrorAggregator") # => "ErrorAggregator"
@return [String]
@api public
# File lib/tty/option/inflection.rb, line 15 def demodulize(name) name.to_s.split("::").last end
underscore(name)
click to toggle source
Convert class name to underscore
@example
underscore("ErrorAggregator") # => "error_aggregator"
@return [String]
@api public
# File lib/tty/option/inflection.rb, line 29 def underscore(name) name.to_s .gsub(/([A-Z\d]+)([A-Z][a-z])/, "\\1_\\2") .gsub(/([a-z\d]+)([A-Z])/, "\\1_\\2") .downcase end
Private Instance Methods
dasherize(name)
click to toggle source
Convert class name to dashed case
@example
dasherize("ErrorAggregator") # => "error-aggregator"
@api public
# File lib/tty/option/inflection.rb, line 44 def dasherize(name) underscore(name).tr("_", "-") end
demodulize(name)
click to toggle source
Remove all modules/class names
@example
demodulize("TTY::Option::ErrorAggregator") # => "ErrorAggregator"
@return [String]
@api public
# File lib/tty/option/inflection.rb, line 15 def demodulize(name) name.to_s.split("::").last end
underscore(name)
click to toggle source
Convert class name to underscore
@example
underscore("ErrorAggregator") # => "error_aggregator"
@return [String]
@api public
# File lib/tty/option/inflection.rb, line 29 def underscore(name) name.to_s .gsub(/([A-Z\d]+)([A-Z][a-z])/, "\\1_\\2") .gsub(/([a-z\d]+)([A-Z])/, "\\1_\\2") .downcase end