Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/locomotive/common/core_ext/string.rb,
lib/locomotive/common/core_ext/string.rb
Instance Method Summary collapse
- #permalink(underscore = false) ⇒ Object
- #permalink!(underscore = false) ⇒ Object (also: #parameterize!)
- #to_bool ⇒ Object
Instance Method Details
#permalink(underscore = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/locomotive/common/core_ext/string.rb', line 18 def permalink(underscore = false) # if the slug includes one "_" at least, we consider that the "_" is used instead of "-". _permalink = if !index('_').nil? to_url(replace_whitespace_with: '_') else to_url end underscore ? _permalink.underscore : _permalink end |
#permalink!(underscore = false) ⇒ Object Also known as: parameterize!
29 30 31 |
# File 'lib/locomotive/common/core_ext/string.rb', line 29 def permalink!(underscore = false) replace(permalink(underscore)) end |
#to_bool ⇒ Object
5 6 7 8 9 10 |
# File 'lib/locomotive/common/core_ext/string.rb', line 5 def to_bool return true if self == true || self =~ (/(true|t|yes|y|1)$/i) return false if self == false || blank? || self =~ (/(false|f|no|n|0)$/i) raise ArgumentError, "invalid value for Boolean: \"#{self}\"" end |