Module: HustleAndFlow::Utils::String

Included in:
Formatters::IssueDetailFormatter, Formatters::IssueTableFormatter
Defined in:
lib/hustle_and_flow/utils/string.rb

Instance Method Summary collapse

Instance Method Details

#titleize(other) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/hustle_and_flow/utils/string.rb', line 15

def titleize(other)
  result = other.to_s.dup
  result = underscore(result)
  result = result.tr('_', ' ')
  result = result.downcase

  result.gsub(/\b(?<!['’`])[a-z]/) { $&.capitalize }
end

#underscore(camel_cased_word) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/hustle_and_flow/utils/string.rb', line 4

def underscore(camel_cased_word)
  word = camel_cased_word.to_s.gsub('::', '/')
  word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}" }
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')
  word.chomp!('_')
  word.downcase!
  word
end