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