Module: SleepingKingStudios::Tools::StringTools
- Extended by:
- StringTools
- Included in:
- StringTools
- Defined in:
- lib/sleeping_king_studios/tools/string_tools.rb
Overview
Tools for working with strings.
Instance Method Summary collapse
-
#pluralize(count, single, plural) ⇒ String
Returns the singular or the plural value, depending on the provided item count.
-
#underscore(str) ⇒ String
Converts a mixed-case string expression to a lowercase, underscore separated string.
Instance Method Details
#pluralize(count, single, plural) ⇒ String
Returns the singular or the plural value, depending on the provided item count.
23 24 25 |
# File 'lib/sleeping_king_studios/tools/string_tools.rb', line 23 def pluralize count, single, plural 1 == count ? single : plural end |
#underscore(str) ⇒ String
Converts a mixed-case string expression to a lowercase, underscore separated string.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sleeping_king_studios/tools/string_tools.rb', line 35 def underscore str require_string! str str = str.dup str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') str.tr!("-", "_") str.downcase! str end |