Class: String
- Defined in:
- lib/jinx/active_support/core_ext/string.rb,
lib/jinx/helpers/inflector.rb,
lib/jinx/helpers/pretty_print.rb,
lib/jinx/helpers/pretty_print.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#capitalize_first ⇒ String
This String with the first letter capitalized and other letters preserved.
-
#decapitalize ⇒ String
This String with the first letter decapitalized and other letters preserved.
-
#indefinitize ⇒ String
This String with a leading indefinite article.
-
#pretty_print(q) ⇒ Object
Pretty-prints this String using the Object pretty_print rather than Enumerable pretty_print.
-
#quantify(quantity) ⇒ String
This String qualified by a plural if the quantity is not 1.
Methods included from ActiveSupport::CoreExtensions::String::Inflections
#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #parameterize, #pluralize, #singularize, #tableize, #titleize, #underscore
Instance Method Details
#capitalize_first ⇒ String
Returns this String with the first letter capitalized and other letters preserved.
17 18 19 |
# File 'lib/jinx/helpers/inflector.rb', line 17 def capitalize_first sub(/(?:^)(.)/) { $1.upcase } end |
#decapitalize ⇒ String
Returns this String with the first letter decapitalized and other letters preserved.
33 34 35 |
# File 'lib/jinx/helpers/inflector.rb', line 33 def decapitalize sub(/(?:^)(.)/) { $1.downcase } end |
#indefinitize ⇒ String
Returns this String with a leading indefinite article.
25 26 27 28 |
# File 'lib/jinx/helpers/inflector.rb', line 25 def indefinitize article = self =~ /^[aeiou]/i ? 'an' : 'a' "#{article} #{self}" end |
#pretty_print(q) ⇒ Object
Pretty-prints this String using the Object pretty_print rather than Enumerable pretty_print.
179 180 181 |
# File 'lib/jinx/helpers/pretty_print.rb', line 179 def pretty_print(q) q.text self end |
#quantify(quantity) ⇒ String
Returns this String qualified by a plural if the quantity is not 1.
9 10 11 12 |
# File 'lib/jinx/helpers/inflector.rb', line 9 def quantify(quantity) raise ArgumentError.new("Missing quantity argument") if quantity.nil? "#{quantity} #{quantity == 1 ? self : pluralize}" end |