Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/piper/string_helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelify(classify = false) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/piper/string_helpers.rb', line 9

def camelify(classify = false)
  if classify
    capitalize
      .gsub(%r{\/(\w)}) { "::" << Regexp.last_match(1).upcase }
      .gsub(/_(\w)/)    { Regexp.last_match(1).upcase }
  else
    split("_").collect(&:capitalize).join
  end
end

#servicifyObject



2
3
4
5
6
7
# File 'lib/piper/string_helpers.rb', line 2

def servicify
  snaked_self = snakify
  return snaked_self if snaked_self.end_with?("_service")

  snaked_self << "_service"
end

#snakifyObject



19
20
21
22
23
24
25
# File 'lib/piper/string_helpers.rb', line 19

def snakify
  gsub(/:{1,2}/, "/")
    .gsub(/([A-Z]+)([A-Z][a-z])/, "\\1_\\2")
    .gsub(/([a-z\d])([A-Z])/, "\\1_\\2")
    .tr("-", "_")
    .downcase
end