module Rafini::String

Public Instance Methods

camel_case() click to toggle source

myNameIsRuby

# File lib/rafini/string.rb, line 13
def camel_case
  pascal_case.tap{_1[0]=_1[0].downcase}
end
camelize(sep='_') click to toggle source

camelize: 1) A camel kick, as in “I gotz camelized”. 2) “a_camel_kick” => “ACamelKick”

# File lib/rafini/string.rb, line 28
def camelize(sep='_')
  warn 'DEPRECATED: use #pascal_case instead'
  split(sep).map(&:capitalize).join
end
kebab_case() click to toggle source

my-name-is-ruby

# File lib/rafini/string.rb, line 21
def kebab_case
  snake_case('-')
end
name_split() click to toggle source
# File lib/rafini/string.rb, line 4
def name_split
  split(/[ _-]|(?=[A-Z])/)
end
pascal_case() click to toggle source

MyNameIsRuby

# File lib/rafini/string.rb, line 8
def pascal_case
  name_split.map(&:capitalize).join
end
semantic(v=(0..2), split:'.', join:'.') click to toggle source

semantic: ‘a.b.c’.semantic(1) #=> ‘b’ ‘a.b.c’.semantic(0..1) #=> ‘a.b’ ‘a.b.c’.semantic(0..2, join:‘/’) #=> ‘b/c’ ‘a/b/c’.semantic(0..2, split:‘/’, join:‘.’) #=> ‘a.b.c’

# File lib/rafini/string.rb, line 38
def semantic(v=(0..2), split:'.', join:'.')
  [*split(split)[v]].join(join)
end
shellescape() click to toggle source

shellescape: Same funtionality as Shellword’s String#shellescape

# File lib/rafini/string.rb, line 44
def shellescape
  # This is a contraction of Shellwords.escape function
  gsub(/[^\w\-.,:+\/@\n]/,'\\\\\\&').gsub(/\n/,"'\n'")
end
snake_case(sep='_') click to toggle source

my_name_is_ruby

# File lib/rafini/string.rb, line 17
def snake_case(sep='_')
  name_split.map(&:downcase).join(sep)
end