Module: PairKit::Miniflector

Defined in:
lib/pair_kit/miniflector.rb,
lib/pair_kit/miniflector/version.rb

Constant Summary collapse

SPLIT_RE =
/(?=[A-Z][a-z]+)|[_\- ]/.freeze
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.camel_case(str) ⇒ Object



4
5
6
# File 'lib/pair_kit/miniflector.rb', line 4

def camel_case(str)
  split(str).map.with_index { |x, i| i.positive? ? x.capitalize : x }.join
end

.kebab_case(str) ⇒ Object



16
17
18
# File 'lib/pair_kit/miniflector.rb', line 16

def kebab_case(str)
  split(str).join('-')
end

.pascal_case(str) ⇒ Object



12
13
14
# File 'lib/pair_kit/miniflector.rb', line 12

def pascal_case(str)
  split(str).map(&:capitalize).join
end

.screaming_kebab_case(str) ⇒ Object



24
25
26
# File 'lib/pair_kit/miniflector.rb', line 24

def screaming_kebab_case(str)
  split(str).map(&:upcase).join('-')
end

.screaming_snake_case(str) ⇒ Object



20
21
22
# File 'lib/pair_kit/miniflector.rb', line 20

def screaming_snake_case(str)
  split(str).map(&:upcase).join('_')
end

.snake_case(str) ⇒ Object



8
9
10
# File 'lib/pair_kit/miniflector.rb', line 8

def snake_case(str)
  split(str).join('_')
end

.split(str) ⇒ Object



30
31
32
# File 'lib/pair_kit/miniflector.rb', line 30

def split(str)
  str.to_s.split(SPLIT_RE).map(&:downcase).map { |x| x.empty? ? nil : x }.compact
end