Class: String
- Defined in:
- lib/roda/component/element.rb,
lib/roda/component/titleize.rb,
lib/roda/component/object/blank.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
- #is_i? ⇒ Boolean
-
#titleize(opts = {}) ⇒ Object
(also: #titlecase)
Capitalizes most words to create a nicer looking title string.
- #titleize! ⇒ Object (also: #titlecase!)
Instance Method Details
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:
''.blank? # => true
' '.blank? # => true
"\t\n\r".blank? # => true
' blah '.blank? # => false
Unicode whitespace is supported:
"\u00a0".blank? # => true
118 119 120 |
# File 'lib/roda/component/object/blank.rb', line 118 def blank? BLANK_RE === self end |
#is_i? ⇒ Boolean
18 19 20 |
# File 'lib/roda/component/element.rb', line 18 def is_i? self.to_i.to_s == self end |
#titleize(opts = {}) ⇒ Object Also known as: titlecase
Capitalizes most words to create a nicer looking title string.
The list of “small words” which are not capped comes from the New York Times Manual of Style, plus ‘vs’ and ‘v’.
titleize is also aliased as titlecase.
"notes on a scandal" # => "Notes on a Scandal"
"the good german" # => "The Good German"
84 85 86 87 88 89 90 |
# File 'lib/roda/component/titleize.rb', line 84 def titleize(opts={}) # if defined? ActiveSupport # ActiveSupport::Inflector.titleize(self, opts) # else Titleize.titleize(self) # end end |
#titleize! ⇒ Object Also known as: titlecase!
93 94 95 |
# File 'lib/roda/component/titleize.rb', line 93 def titleize! replace(titleize) end |