Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/common/core_ext/string.rb,
lib/locomotive/common/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details



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_boolObject

Raises:

  • (ArgumentError)


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