Module: SimplerCommand::StringUtils
- Defined in:
- lib/simpler_command/string_utils.rb
Overview
Simple Utilities for either using ActiveSupport methods, or falling back to equivalents.
Used only for generating Human-readable Strings, which should not be used for logic
Class Method Summary collapse
-
.humanize(string) ⇒ Object
Converts a string to a human-readable string.
-
.to_sentence(array) ⇒ Object
Attempt Array#to_sentence provided by ActiveSupport, or fall back to join.
Class Method Details
.humanize(string) ⇒ Object
Converts a string to a human-readable string
11 12 13 14 15 16 17 18 |
# File 'lib/simpler_command/string_utils.rb', line 11 def humanize(string) attribute = string.tr(".", "_") if attribute.respond_to?(:humanize) attribute.humanize else attribute.tr("_", " ").capitalize end end |
.to_sentence(array) ⇒ Object
Attempt Array#to_sentence provided by ActiveSupport, or fall back to join
21 22 23 24 25 26 27 |
# File 'lib/simpler_command/string_utils.rb', line 21 def to_sentence(array) if array.respond_to?(:to_sentence) array.to_sentence else array.join(", ") end end |