Module: DuckPuncher::Ducks::String

Defined in:
lib/duck_puncher/ducks/string.rb

Constant Summary collapse

BOOLEAN_MAP =
::Hash[%w(true 1 yes y on).product([true])].freeze

Instance Method Summary collapse

Instance Method Details

#constantizeObject



18
19
20
# File 'lib/duck_puncher/ducks/string.rb', line 18

def constantize
  split('::').inject(Object) { |o, name| o.const_get name }
end

#pluralize(count) ⇒ Object



6
7
8
# File 'lib/duck_puncher/ducks/string.rb', line 6

def pluralize(count)
  "#{self}#{'s' if count != 1}"
end

#to_booleanObject



14
15
16
# File 'lib/duck_puncher/ducks/string.rb', line 14

def to_boolean
  !!BOOLEAN_MAP[downcase]
end

#underscoreObject



10
11
12
# File 'lib/duck_puncher/ducks/string.rb', line 10

def underscore
  gsub(/\B([A-Z])([a-z_0-9])/, '_\1\2').gsub('::', '/').downcase
end